2
我想使用Google地圖繪製折線。
我已經閱讀了API並做了一些研究,但我仍然留下了一個基本問題。
信息:
谷歌地圖折線:從原始點計算端點
lat: 63.43243500
lon: 10.37045667
angle: 230 degrees (0 = north)
我怎樣才能使一個折線是長60米,從原來的經/緯度起源具有230度的角度?
我想使用Google地圖繪製折線。
我已經閱讀了API並做了一些研究,但我仍然留下了一個基本問題。
信息:
谷歌地圖折線:從原始點計算端點
lat: 63.43243500
lon: 10.37045667
angle: 230 degrees (0 = north)
我怎樣才能使一個折線是長60米,從原來的經/緯度起源具有230度的角度?
您需要計算(lat,lon)中該行的終點。這可以使用google.maps.geometry.spherical namespace中的calculateOffset
函數完成。它有三個必需的參數:起始緯度/經度點,行程距離和航向角度。
這裏是您的具體情況爲例:
var startLL = new google.maps.LatLng(63.43243500,10.37045667);
var endLL = new google.maps.geometry.spherical.computeOffset(startLL, 60, 230);
從the Polyline example,您可以創建這些點的折線爲:
var coordinates = [startLL, endLL];
var path = new google.maps.Polyline({
path: coordinates,
strokeColor: "#FF0000",
strokeOpacity: 1.0,
strokeWeight: 2
});
更新:您還需要使確定你包含了默認不包含的geometry
庫。繼說明here,您需要更改您的引導請求:
http://maps.google.com/maps/api/js?libraries=geometry&sensor=false
它不工作,這是我的[小提琴](http://jsfiddle.net/3CvaD/77/) – HyperDevil 2011-02-25 19:29:20
@HyperDevil - 好吧,我明白了這一點。這是一個有點棘手,因爲我從來沒有使用JavaScript或谷歌地圖API。你需要確保你添加了'geometry'庫。看到我上面的編輯。 [這是一個更正的小提琴](http://jsfiddle.net/3CvaD/85/) – Justin 2011-02-25 19:43:19