【问题标题】:Displaying google maps pinpoints near a certain specified location在某个指定位置附近显示谷歌地图的精确定位
【发布时间】:2011-01-17 07:30:38
【问题描述】:

我有一张桌子,上面有一些位置。例如:

ID    LAT        LNG
1     40.759139  -73.979723

我正在尝试从他的 IP 地址获取用户的国家和城市(假设我有它,它是德国,例如柏林)。

然后遍历我的数据库中的所有位置并选择靠近或在该城市内(在城市内更好)并以这种方式将它们显示在地图上:http://code.google.com/apis/maps/documentation/javascript/examples/event-closure.html

现在我看到了这个问题: how do i find near by locations to a given location using google map api

这不是我真正想要的,虽然它很接近。

有人知道我怎样才能完成我想做的事情吗?

谢谢,

【问题讨论】:

    标签: javascript google-maps google-maps-api-3


    【解决方案1】:

    想通了,这就是你的做法:

    注意:$default 包含您最初希望显示的城市纬度/经度。 mapEvents() 返回一个包含事件的所有 lat/lng/title 的数组。

    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> 
    
        <script type="text/javascript"> 
        var map;
        function initialize() {
          var myLatlng = new google.maps.LatLng(<?= $default ?>);
          var myOptions = {
            zoom: 9,
            center: myLatlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
          }
    
          map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
        <?php
            $pinpoints = mapEvents();
            foreach ($pinpoints as $pinpoint) {
                $loc = $pinpoint['UA_LAT'] . "," . $pinpoint['UA_LNG'];
                echo("
                     var myLatlng = new google.maps.LatLng(" . $loc . ");
                     var marker = new google.maps.Marker({
                         position: myLatlng, 
                         map: map,
                         title: '" . $pinpoint['EVENT_NAME'] . "'
                         });
                     ");
                $loc = "";
            }
        ?>
        }
        </script>
    

    【讨论】:

      猜你喜欢
      • 2011-03-30
      • 1970-01-01
      • 2016-04-23
      • 2013-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-16
      • 1970-01-01
      相关资源
      最近更新 更多