2013-07-10 58 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

相关问题