【发布时间】:2018-03-31 08:34:45
【问题描述】:
首先我要感谢所有可以帮助我的人,并说我是开发的初学者。
我正在尝试为 具有地理定位功能的 Google 地图设置代码,该地图仅显示租车类型地点的标记。这个想法是,当我的网页访问者进入该网站时,地图会地理定位访问者的位置,并且地图仅显示附近的汽车租赁地点。
我得到了地理定位谷歌代码:
<div id="map" style="width: 100%; height: 500px;"></div>
<script>
// Note: This example requires that you consent to location sharing when
// prompted by your browser. If you see the error "The Geolocation service
// failed.", it means you probably did not give permission for the browser to
// locate you.
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644},
zoom: 6
});
var infoWindow = new google.maps.InfoWindow({map: map});
// Try HTML5 geolocation.
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
infoWindow.setPosition(pos);
infoWindow.setContent('Location found.');
map.setCenter(pos);
}, function() {
handleLocationError(true, infoWindow, map.getCenter());
});
} else {
// Browser doesn't support Geolocation
handleLocationError(false, infoWindow, map.getCenter());
}
}
function handleLocationError(browserHasGeolocation, infoWindow, pos) {
infoWindow.setPosition(pos);
infoWindow.setContent(browserHasGeolocation ?
'Error: The Geolocation service failed.' :
'Error: Your browser doesn\'t support geolocation.');
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=[MYAPIKEY]&callback=initMap">
</script>
它工作正常,但现在,我正在阅读有关地点和类型的信息,但我没有成功。
有什么想法吗?有人可以帮帮我吗?
提前致以最诚挚的问候和感谢。
乔迪五世。 CarRentals.Deals
【问题讨论】:
标签: google-maps-api-3 types geolocation google-places-api