【发布时间】:2016-12-08 22:42:36
【问题描述】:
我正在使用带有 HTML5 地理位置的 infoWindow 的谷歌地图示例,并希望在地图上添加一个圆形标记以显示用户位置而不是 infoWindow 文本框。
我用谷歌搜索了但没有找到答案,这可能吗?
var map;
function initMap(){
map = new google.maps.Map(document.getElementById('map'), {
zoom: 6
});
var infoWindow = new google.maps.Circle({map: map});
// Try HTML5 geolocation.
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var pos = {
lat: position.coords.latitude,
lng: position.coords.longitude,
};
infoWindow.setCenter(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.');
}
}
【问题讨论】:
-
是的,有可能,你希望圈子有多大?通知
google.maps.Marker或google.maps.Circle?。你有没有尝试过? -
我已经搞砸了几个小时。我希望它是一个maps.Circle。我不关心分钟的大小,以后可以玩。只想要工作代码
标签: javascript google-maps geolocation