0
假設我知道公路A的起始緯度/經度,並且建築區域從公里175開始。 有沒有辦法計算緯度/經度在175公里處? (可能與方向服務)谷歌地圖:從已知的起始位置獲取緯度/經度公里
假設我知道公路A的起始緯度/經度,並且建築區域從公里175開始。 有沒有辦法計算緯度/經度在175公里處? (可能與方向服務)谷歌地圖:從已知的起始位置獲取緯度/經度公里
Mike Williams寫了一個擴展名爲Google Maps Javascript API v2 (now deprecated and turned off)其中epoly包含方法.GetPointAtDistance,這你想要做什麼。所述GetPointAtDistance功能的
example using a ported version of that library
部分源代碼(取決於延伸與distanceFrom方法google.maps.LatLng對象)
/* .GetPointAtDistance() returns a google.maps.LatLng at the specified distance *
* along the path. *
* The distance is specified in metres *
* Returns null if the path is shorter than that *
*/
// === A method which returns a google.maps.LatLng of a point a given distance along the path ===
// === Returns null if the path is shorter than the specified distance ===
google.maps.Polygon.prototype.GetPointAtDistance = function(metres) {
// some awkward special cases
if (metres == 0) return this.getPath().getAt(0);
if (metres < 0) return null;
if (this.getPath().getLength() < 2) return null;
var dist=0;
var olddist=0;
for (var i=1; (i < this.getPath().getLength() && dist < metres); i++) {
olddist = dist;
dist += this.getPath().getAt(i).distanceFrom(this.getPath().getAt(i-1));
}
if (dist < metres) {
return null;
}
var p1= this.getPath().getAt(i-2);
var p2= this.getPath().getAt(i-1);
var m = (metres-olddist)/(dist-olddist);
return new google.maps.LatLng(p1.lat() + (p2.lat()-p1.lat())*m, p1.lng() + (p2.lng()-p1.lng())*m);
}
像[本](HTTP://www.geocodezip。 COM/v3_GoogleEx_directions-waypoints_kmmarkersC.html)? – geocodezip
像往常一樣好「回答」! – MrUpsidown
@geocodezip謝謝。 polyline.GetPointAtDistance實際上是我需要的,但我無法在Polyline API v3中找到此功能。 – bardu