2013-07-10 56 views
0

我試圖計算我的路線,從我的當前位置到特定位置(var:end)。我想如何從我目前的位置獲得我的LatLng? THX如何獲得GMAPS API V3的當前經緯度位置?

這裏是我的代碼:

function calcRoute() { 
var start = "How to get this LatLng ?"; 
var end = new google.maps.LatLng(-6.28529,106.871542); 
var request = { 
    origin:start, 
    destination:end, 
    travelMode: google.maps.TravelMode.WALKING 
}; 

directionsService.route(request, function(result, status) { 
    if (status == google.maps.DirectionsStatus.OK) { 
     directionsDisplay.setDirections(result); 
     } 
    }); 
} 
+0

您需要使用手機上的gps。下面是如何設置它的鏈接:http://developer.android.com/guide/topics/location/strategies.html – Scott

+0

我得到了我的設備位置,但我只需要Lat和Lng號碼?怎麼樣 ? – user2565280

回答

0

如果你有一個定位對象(可以調用它的位置),所有你需要做的是LatLng mLatLng = new LatLng(location.getLatitude(), location.getLongitude()),你將有一個經緯度對象。 location.getLatitude()返回一個以度爲單位的緯度對應的雙精度值,而location.getLongitude()返回相同的經度。有關更多詳細信息,請參閱文檔:http://developer.android.com/reference/android/location/Location.html

+0

哇:)非常感謝 – user2565280

相關問題