![](/img/trans.png)
[英]Calculate the distance between my current location and user locations from API with Google Maps API DistanceMatrixService
[英]Calculate the distance between 2 position Google maps Api
我們要創建一個我們城市的Line Bus,我們可以使用什么樣的Maps Api,我的朋友建議使用Google Map Api。 我們想知道如何以米為單位獲得 2 個地方之間的距離,我找到了 distanceFrom() 方法,它生成了空氣中的距離,而不是街道之間的距離。 我們有一個地址表,我們想將它與來自用戶的位置進行比較以找到最近的地址。 所以我們需要找到位置和表中所有地址列表之間的較低距離。
我的代碼是使用 google map deriction 服務在地圖中獲得 2 點或 2 個位置的距離
var PolylineOption = {
strokeColor : "blue",
strokeOpacity : 0.5,
strokeWeight : 5
};
var request = {
origin : polyline[0].start, // điểm đầu
waypoints : polyline[1].waypoint,
destination : polyline[2].end, // Điểm cuối
optimizeWaypoints : true,
travelMode : google.maps.TravelMode.DRIVING
};
rendererOptions = {
draggable : true,
suppressMarkers : true,
polylineOptions : this.PolylineOption
};
var Service = new google.maps.DirectionsService();
var Display = new google.maps.DirectionsRenderer(rendererOptions);
Display.setMap(map);
Service.route(this.request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
distance += response.routes[0].legs[0].distance.value;
// distance of 2 location
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.