【问题标题】:Google Maps API V3, Is this a good solution for snapping marker to road?Google Maps API V3,这是将标记捕捉到道路的好解决方案吗?
【发布时间】: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
        });
    });` 

这是基于用户点击将标记捕捉到道路的好方法吗?是还是不是?有没有更好的办法?

【问题讨论】:

标签: javascript maps


【解决方案1】:

如果你使用,你可以为自己节省三行代码:

position: response.routes[0].legs[0].start_location

现在您正在使用 LatLng 对象的各个统计信息来创建新的 LatLng 对象

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-27
    • 2018-12-01
    • 2011-06-15
    • 1970-01-01
    • 1970-01-01
    • 2014-04-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多