javascript - 谷歌地图记录每一条记录

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

这是我的情况:

我的数据库中有诊所。问题是我想在谷歌地图中显示每个诊所的位置。

我尝试了几种方法,但没有奏效。仅显示一个诊所,而不是所有诊所。

我的问题:是否可能,如果可能,如何实现?

提前致谢(抱歉我的英语不好)。

最佳答案

是的,这是可能的,您应该为此使用谷歌地图 API。这是我用于类似任务的 php 文件。我可以使用它在 map 上显示不同的城市。您可以从数据库中获取坐标。

还有一个类似的问题您应该检查:Google Maps JS API v3 - Simple Multiple Marker Example

    <!DOCTYPE html>
    <html> 
    <head> 
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> 
    <title>Google Maps Multiple Markers</title> 
    <script src="http://maps.google.com/maps/api/js?sensor=false" 
          type="text/javascript"></script>
    </head> 
    <body>
    <div id="map" style="width: 500px; height: 400px;"></div>

     <script type="text/javascript">
     var locations = [
      ['Bondi Beach', -33.890542, 151.274856, 4],
      ['Coogee Beach', -33.923036, 151.259052, 5],
      ['Cronulla Beach', -34.028249, 151.157507, 3],
      ['Manly Beach', -33.80010128657071, 151.28747820854187, 2],
      ['Maroubra Beach', -33.950198, 151.259302, 1]
    ];

    var map = new google.maps.Map(document.getElementById('map'), {
      zoom: 10,
      center: new google.maps.LatLng(-33.92, 151.25),
      mapTypeId: google.maps.MapTypeId.ROADMAP
    });

    var infowindow = new google.maps.InfoWindow();

    var marker, i;

    for (i = 0; i < locations.length; i++) {  
      marker = new google.maps.Marker({
        position: new google.maps.LatLng(locations[i][1], locations[i][2]),
        map: map,
        icon: 'zcx.jpg'
      });

      google.maps.event.addListener(marker, 'click', (function(marker, i) {
        return function() {
          infowindow.setContent(locations[i][0]);
          infowindow.open(map, marker);
        }
      })(marker, i));
    }
  </script>
</body>
</html>

关于javascript - 谷歌地图记录每一条记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30260738/

相关文章:

javascript - Cordova 从服务器加载外部内容

javascript - Google map 使用 AJAX 添加标记

javascript - 如何使用多个参数过滤对象数组

javascript - Node/异步 : how to keep my code easy to understand

javascript - 获取变量中的字符串以在 Javascript 中创建动态链接

php - 使用 Nginx 而不是 Apache 时,单独的 MySQL 服务器是否有意义?

php - 由于 index.php 导致 Codeigniter 500 内部服务器错误

PHP:使用 preg_match() 匹配奇怪的破折号

java - 查找出发地 LatLng 和目的地 LatLng 之间的行驶距离

javascript - Google Maps API V3 - 在创建标记后添加监听器