Javascript 谷歌地图没有显示在Safari 5.1.7中
它在Chrome、IE和Fire fox中完美地显示了地图,但在Safari版本5.1.7中没有显示地图。有人能帮我解决这个问题吗 我的谷歌地图JavaScriptJavascript 谷歌地图没有显示在Safari 5.1.7中,javascript,Javascript,它在Chrome、IE和Fire fox中完美地显示了地图,但在Safari版本5.1.7中没有显示地图。有人能帮我解决这个问题吗 我的谷歌地图JavaScript <script> function writeAddressName(latLng) { var geocoder = new google.maps.Geocoder(); geocoder.geocode({ "location": latLng }, fun
<script>
function writeAddressName(latLng) {
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ "location": latLng },
function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
}
else
document.getElementById("error").innerHTML += "Unable to retrieve your address" + "<br />";
});
}
function geolocationSuccess(position) {
var userLatLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
document.cookie = "latitude=" + position.coords.latitude;
document.cookie = "longitude=" + position.coords.longitude;
// Write the formatted address
writeAddressName(userLatLng);
var myOptions = {
zoom: 16,
center: userLatLng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
scrollwheel: false
};
// Draw the map
var mapObject = new google.maps.Map(document.getElementById("map"), myOptions);
// Place the marker
new google.maps.Marker({
map: mapObject,
position: userLatLng
});
// Draw a circle around the user position to have an idea of the current localization accuracy
var circle = new google.maps.Circle({
center: userLatLng,
//radius: position.coords.accuracy,
map: mapObject,
//fillColor: '#0000FF',
fillOpacity: 0.5,
//strokeColor: '#0000FF',
strokeOpacity: 1.0
});
mapObject.fitBounds(circle.getBounds());
}
function geolocationError(positionError) {
document.getElementById("error").innerHTML + positionError.message + "<br />";
}
function geolocateUser() {
// If the browser supports the Geolocation API
if (navigator.geolocation) {
var positionOptions = {
enableHighAccuracy: true,
timeout: 10 * 1000 // 10 seconds
};
navigator.geolocation.getCurrentPosition(geolocationSuccess, geolocationError, positionOptions);
}
else
document.getElementById("error").innerHTML += "Your browser doesn't support the Geolocation API";
}
window.onload = geolocateUser;
</script>
函数writedDressName(latLng){
var geocoder=new google.maps.geocoder();
地理编码器。地理编码({“位置”:latLng},
功能(结果、状态){
if(status==google.maps.GeocoderStatus.OK){
}
其他的
document.getElementById(“错误”).innerHTML+=“无法检索您的地址”+”
”;
});
}
功能地理定位成功(职位){
var userLatLng=new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
document.cookie=“latitude=“+position.coords.latitude;
document.cookie=“longitude=“+position.coords.longitude;
//写格式化的地址
writeAddressName(userLatLng);
变量myOptions={
缩放:16,
中心:userLatLng,
mapTypeId:google.maps.mapTypeId.ROADMAP,
滚轮:错误
};
//画地图
var mapObject=new google.maps.Map(document.getElementById(“Map”),myOptions);
//放置标记
新的google.maps.Marker({
map:mapObject,
职位:userLatLng
});
//围绕用户位置画一个圆圈,了解当前定位精度
var circle=new google.maps.circle({
中心:userLatLng,
//半径:位置、坐标、精度,
map:mapObject,
//填充颜色:“#0000FF”,
填充不透明度:0.5,
//strokeColor:“#0000FF”,
笔划不透明度:1.0
});
fitBounds(circle.getBounds());
}
函数地理位置错误(位置错误){
document.getElementById(“error”).innerHTML+positionError.message+“
”;
}
函数geolocateUser(){
//如果浏览器支持地理定位API
if(导航器.地理位置){
变量位置选项={
EnableHighAccurance:正确,
超时:10*1000//10秒
};
navigator.geolocation.getCurrentPosition(geolocationSuccess、geolocationError、positionOptions);
}
其他的
document.getElementById(“错误”).innerHTML+=“您的浏览器不支持地理位置API”;
}
window.onload=地理位置用户;
谢谢。您的地图只有在地理定位成功时才会绘制,但至少对我来说,它在Safari中失败了 不是在
geolocationSuccess
中创建地图,而是首先使用默认中心创建地图,并在geolocation成功时更新地图中心
函数geolocateUser(){
//绘制地图:
变量myOptions={
缩放:1,
中心:{
纬度:0,
液化天然气:0
},//开始时的默认中心
mapTypeId:google.maps.mapTypeId.ROADMAP,
滚轮:错误
};
//画地图
var mapObject=new google.maps.Map(document.getElementById(“Map”),myOptions);
//放置标记
控件[google.maps.ControlPosition.TOP_CENTER].push(document.getElementById('error');
函数writedDressName(latLng){
var geocoder=new google.maps.geocoder();
地理编码({
“位置”:latLng
},
功能(结果、状态){
if(status==google.maps.GeocoderStatus.OK){
document.getElementById(“错误”)
.innerHTML=results[0]。格式化的\u地址;
}否则
document.getElementById(“错误”)
.innerHTML=“无法检索您的地址”;
});
}
功能地理定位成功(职位){
var userLatLng=new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
新的google.maps.Marker({
map:mapObject,
职位:userLatLng
});
//围绕用户位置画一个圆圈,了解当前定位精度
var circle=new google.maps.circle({
中心:userLatLng,
半径:位置、坐标、精度,
map:mapObject,
//填充颜色:“#0000FF”,
填充不透明度:0.5,
//strokeColor:“#0000FF”,
笔划不透明度:1.0
});
fitBounds(circle.getBounds());
writeAddressName(userLatLng);
}
函数地理位置错误(位置错误){
变量e={
1:'权限被拒绝',
2:“位置不可用”,
3:“超时”
};
document.getElementById(“error”).innerHTML='error:'+e[positionError.code];
}
//如果浏览器支持地理定位API
if(导航器.地理位置){
变量位置选项={
EnableHighAccurance:正确,
超时:10*1000//10秒
};
geolocation['getCurrent'+'Position'](geolocationSuccess、geolocationError、positionOptions);
}否则{
document.getElementById(“error”).innerHTML=“您的浏览器不支持地理位置API”;
}
}
window.onload=地理位置用户代码>
html,
身体,
#地图{
身高:100%;
保证金:0;
填充:0
}
#错误{
背景:#fff;
填充:6px;
}
非常感谢您的回复,莫勒博士。我是谷歌地图的新手。所以,你能解释一下我的脚本中的问题吗?正如我所说,地理定位可能会失败,当它失败时,你的脚本不会创建地图。这与其说是脚本错误,不如说是逻辑错误。很抱歉打扰你,你能指出我在脚本中做了哪些更改吗?你能在所有浏览器中共享任何支持谷歌地图的链接吗。这将有助于我识别我的错误。谢谢,这不是谷歌地图或特定浏览器的问题(地理定位可能在任何浏览器中失败或被用户拒绝)。我在上面添加了一个示例