【发布时间】:2012-05-01 18:34:47
【问题描述】:
所以我正在开发一个移动应用程序,并且一直在研究让标记捕捉到您在地图上点击的最近道路的最简单方法。我想出了以下解决方案,在网上的任何地方都没有看到它,只是想看看这样做有什么问题吗?
我会发布我的代码,但它散布在几个对象中。这就是它的要点。
所以基本上... - 为返回您点击的纬度/经度坐标的地图建立点击处理程序(简单)
然后像.. `var DirectionsService = new google.maps.DirectionsService();
DirectionsService.route({
'origin': clickLatLngPosition,
'destination': clickLatLngPosition,
'travelMode': google.maps.TravelMode.DRIVING
}, function(response, status){
testLat = response.routes[0].legs[0].start_location.lat();
testLng = response.routes[0].legs[0].start_location.lng();
testPosition = new google.maps.LatLng(testLat, testLng);
slammedNavigator.snMapElement.gmap('addMarker', {
'position': testPosition
});
});`
这是基于用户点击将标记捕捉到道路的好方法吗?是还是不是?有没有更好的办法?
【问题讨论】:
-
相关:stackoverflow.com/questions/4804495/…使用方向是常用的方法。
标签: javascript maps