gmaps.js使用地址代替纬度经度 [英] gmaps.js using address instead of latitude longitude
本文介绍了gmaps.js使用地址代替纬度经度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
map = new GMaps({
el: '#map',
zoom:16,
disableDefaultUI:true,
lat:{{$ loc-> latitude}},
lng:{{$ loc-> gt ; longitude}}
});
map.addMarker({
lat:{{$ loc-> latitude}},
lng:{{$ loc-> longitude}},
title:' {{$ loc-> name}}',
infoWindow:{
content:'< p> {{$ loc-> name}}< / p>'
}
});
解决方案
使用 Geocoder 将地址转换为地图上可以使用的地理坐标。
相关问题:使用用Google Maps API代替经度和纬度
GMaps.js示例:
代码片段:
body,html {width:100%; height:100%;}。map {width:100%; height:100%;}
< script src = https://maps.googleapis.com/maps/api/js\"></script><script src =https://hpneo.github.io/gmaps/gmaps.js>< /脚本>< div class =map>< / div>
appreciate any help, Im using http://hpneo.github.io/gmaps/ and I was wondering if its possible to use the address instead of latitude longitude
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>'
}
});
解决方案
Use the Geocoder to translate an address into geographic coordinates that can be used on a map.
Related question: Using Address Instead Of Longitude And Latitude With Google Maps API
Example with GMaps.js:
code snippet:
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);
body, html {
width: 100%;
height: 100%;
}
.map {
width: 100%;
height: 100%;
}
<script src="https://maps.googleapis.com/maps/api/js"></script>
<script src="https://hpneo.github.io/gmaps/gmaps.js"></script>
<div class="map"></div>
这篇关于gmaps.js使用地址代替纬度经度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文