gmaps.js使用地址而不是纬度经度

时间:2016-02-26 15:12:44

标签: google-maps

感谢任何帮助,我正在使用http://hpneo.github.io/gmaps/,我想知道是否可以使用地址而不是纬度经度

  map = new GMaps({
    el: '#map',
    zoom: 16,
    disableDefaultUI: true,
    lat: {{ $loc->latitude }},
    lng: {{ $loc->longitude }}
  });
  map.addMarker({
    lat: {{ $loc->latitude }},
    lng: {{ $loc->longitude }},
    title: '{{ $loc->name }}',
    infoWindow: {
      content: '<p>{{ $loc->name }}</p>'
    }
  });

1 个答案:

答案 0 :(得分:1)

使用Geocoder将地址转换为可在地图上使用的地理坐标。

相关问题:Using Address Instead Of Longitude And Latitude With Google Maps API

proof of concept fiddle

GMaps.js示例:

代码段

&#13;
&#13;
function initialize() {
/*Maps*/
var map = new GMaps({
      div: '.map',
      lat: 0, 
      lng: 0,
      zoom: 0
});

GMaps.geocode({
  address: "Oradell, NJ",
  callback: function(results, status) {
    if (status == 'OK') {
      var latlng = results[0].geometry.location;
      map.fitBounds(results[0].geometry.viewport);
      map.addMarker({
        lat: latlng.lat(),
        lng: latlng.lng()
      });
    }
  }
});

}
google.maps.event.addDomListener(window, "load", initialize);
&#13;
body, html {
  width: 100%;
  height: 100%;
}

.map {
  width: 100%;
  height: 100%;
}
&#13;
<script src="https://maps.googleapis.com/maps/api/js"></script>
<script src="https://hpneo.github.io/gmaps/gmaps.js"></script>
<div class="map"></div>
&#13;
&#13;
&#13;

相关问题