Javascript 谷歌地图地理定位在Safari中工作,但在其他浏览器(Chrome、Firefox、Opera、IE)中不工作
我有一个网站,我正在建设的问题。我正在尝试设置一个谷歌地图,显示一个阴影区域作为企业的服务区域,我还想做的是设置地理位置,在用户位置放置一个pin,以便他们可以看到他们是否在服务区域内 下面的代码完全按照我在Safari中希望的方式工作,但是,它在其他浏览器(如Chrome、IE、Firefox)上只能获得一个通用位置(在市中心) 我对网络开发还很陌生,只是在学习,所以我有点困惑为什么会这样 谢谢你,阿什Javascript 谷歌地图地理定位在Safari中工作,但在其他浏览器(Chrome、Firefox、Opera、IE)中不工作,javascript,google-maps,Javascript,Google Maps,我有一个网站,我正在建设的问题。我正在尝试设置一个谷歌地图,显示一个阴影区域作为企业的服务区域,我还想做的是设置地理位置,在用户位置放置一个pin,以便他们可以看到他们是否在服务区域内 下面的代码完全按照我在Safari中希望的方式工作,但是,它在其他浏览器(如Chrome、IE、Firefox)上只能获得一个通用位置(在市中心) 我对网络开发还很陌生,只是在学习,所以我有点困惑为什么会这样 谢谢你,阿什 `var locations = []; var map, marker,
`var locations = [];
var map,
marker,
infowindow;
function initialize() {
infowindow = new google.maps.InfoWindow();
var myOptions = {
zoom: 12,
preserveViewport: true,
center: new google.maps.LatLng(-26.720774, 153.084475),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("googleMap"), myOptions);
var triangleCoords = [
new google.maps.LatLng(-26.636872, 153.101323),
new google.maps.LatLng(-26.631348, 153.070424),
new google.maps.LatLng(-26.659732, 153.065618),
new google.maps.LatLng(-26.673538, 152.998498),
new google.maps.LatLng(-26.687343, 153.003819),
new google.maps.LatLng(-26.709887, 153.021157),
new google.maps.LatLng(-26.722920, 153.044847),
new google.maps.LatLng(-26.773354, 153.043473),
new google.maps.LatLng(-26.791130, 153.121408),
new google.maps.LatLng(-26.791590, 153.148187),
new google.maps.LatLng(-26.783775, 153.140634),
new google.maps.LatLng(-26.733959, 153.135286),
new google.maps.LatLng(-26.679981, 153.138917),
new google.maps.LatLng(-26.677373, 153.118318)
];
reflectshinesServiceArea = new google.maps.Polygon({
paths: triangleCoords,
strokeColor: '#6ab47b',
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: '#6ab47b',
fillOpacity: 0.35
});
reflectshinesServiceArea.setMap(map);
set_current_location();
}
function add_location(description, latitude, longtitude) {
locations.push([description, latitude, longtitude]);
}
function set_markers(fitbounds, map) {
for (var i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map
});
fitbounds.extend(marker.position);
google.maps.event.addListener(marker, 'click', (function (marker, i) {
return function () {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
}
function set_current_location() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
add_location('My location',
position.coords.latitude,
position.coords.longitude);
set_markers(new google.maps.LatLngBounds(), map);
}, function error(err) {
console.log('error: ' + err.message);
set_markers(new google.maps.LatLngBounds(), map);
});
} else {
alert("Geolocation is not supported by this browser.");
}
}
`
`var locations=[];
var映射,
标记,
信息窗口;
函数初始化(){
infowindow=new google.maps.infowindow();
变量myOptions={
缩放:12,
对,,
中心:新google.maps.LatLng(-26.720774153.084475),
mapTypeId:google.maps.mapTypeId.ROADMAP
};
map=new google.maps.map(document.getElementById(“谷歌地图”),myOptions);
var triangleCoords=[
新的google.maps.LatLng(-26.636872153.101323),
新的google.maps.LatLng(-26.631348153.070424),
新的google.maps.LatLng(-26.659732153.065618),
新的google.maps.LatLng(-26.673538152.998498),
新的google.maps.LatLng(-26.687343153.003819),
新google.maps.LatLng(-26.709887153.021157),
新google.maps.LatLng(-26.72292053.044847),
新google.maps.LatLng(-26.773354153.043473),
新google.maps.LatLng(-26.791130153.121408),
新google.maps.LatLng(-26.791590153.148187),
新的google.maps.LatLng(-26.783775153.140634),
新google.maps.LatLng(-26.733959153.135286),
新google.maps.LatLng(-26.679981153.138917),
新google.maps.LatLng(-26.677373153.118318)
];
reflectshinesServiceArea=新建google.maps.Polygon({
路径:三角形门,
strokeColor:“#6ab47b”,
笔划不透明度:0.8,
冲程重量:2,
填充颜色:“#6ab47b”,
不透明度:0.35
});
reflectshinesServiceArea.setMap(映射);
设置当前位置();
}
功能添加位置(说明、纬度、经度){
位置。推力([说明,纬度,经度]);
}
函数集\u标记(fitbounds,map){
对于(变量i=0;i
尝试清除浏览器中的casheThanks对于建议,我清除了缓存,没有乐趣,但我在另一个位置与另一个用户进行了测试,结果更好,但仍然不太准确。它一定是我电脑本地的其他东西。