2014-07-08 43 views
-6

我們想要創建一個我們城市的線路巴士,我們可以使用什麼樣的Maps Api,我的朋友使用Google Map Api。 我們想要知道如何獲得米的距離beetwen 2個地方,我找到了distanceFrom()方法,並且它在空中而不是beetwen街產生距離。 我們有一張地址表,我們希望將它與來自用戶的位置進行比較以找到最近的地址。所以我們需要找到位置和表格中所有地址列表的較低距離。 謝謝計算距離beetwen 2個位置的Googla地圖Api

+0

聽起來像是你正在尋找[DirectionsMatrix(https://developers.google。 com/maps/documentation/javascript/distancematrix)(也是一個[Web服務](https://developers.google.com/maps/documentation/distancematrix/)。但是有一些限制,它是否會起作用取決於多少您需要距離的位置。 – geocodezip

回答

0

我的代碼得到地圖谷歌地圖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 
     } 
    });