Safari 5.1.7中的地理位置不起作用 [英] Geolocation in Safari 5.1.7 doesn't work
问题描述
我试图在我的ASP MVC网站中使用navigator.geolocation.getCurrentPosition()但它在Safari上不起作用。它在IE,Chrome,Opera或Mozilla上完美运行。这就是我的尝试:
< div id = content > < / div >
< script type = text / javascript >
$( document )。ready( function (){
function showPosition(position){
alert( showPosition);
console .log( 纬度: + position.coords.latitude + < br>经度: +位置。 coords.longitude);
var latitude = position.coords.latitude;
var 经度= position.coords.longitude;
$ .ajax({
type: POST ,
url:' / Home / Coordinates',
data:
{
纬度:纬度,
经度:经度
},
成功:功能(数据){
$( #content)。html(data);
},
错误: function (){
alert( 错误);
}
});
}
if ( navigator .geolocation){
alert( 支持地理位置);
navigator .geolocation.getCurrentPosition(showPosition, function (错误){
alert ( 错误);
},
{maximumAge: 12000000 ,超时: 30000 });
}
else {
alert( 没有支持);
console .log( 地理定位不是这个浏览器支持。);
}
});
< / script >
在Safari上它不会调用 showposition()功能,但它总是以警告(错误)结束。有谁知道为什么或我在这里做错了什么?谢谢。
( document )。ready( function (){
function showPosition(position){
alert( showPosition);
console .log( 纬度: + position.coords.latitude + < br>经度: + position.coords.longitude);
var latitude = position.coords.latitude;
var 经度= position.coords.longitude;
.ajax ({
类型: POST,
u rl:' / Home / Coordinates',
data:
{
纬度:纬度,
经度:经度
},
成功:功能(数据){
( #content)。html(data);
},
错误: function (){
alert( 错误);
}
});
}
if ( navigator .geolocation){
alert( 支持地理位置);
navigator .geolocation.getCurrentPosition(showPosition, function (错误){
alert ( 错误);
},
{maximumAge: 12000000 ,超时: 30000 });
}
else {
alert( 没有支持);
console .log( 地理定位不是这个浏览器支持。);
}
});
< / script >
在Safari上它不会调用 showposition()功能,但它总是以警告(错误)结束。有谁知道为什么或我在这里做错了什么?感谢。
I tried to use "navigator.geolocation.getCurrentPosition()" in my ASP MVC site but it doesn't work on Safari. It's working perfectly on IE, Chrome, Opera or Mozilla. This is what I tried:
<div id="content"></div>
<script type="text/javascript">
$(document).ready(function () {
function showPosition(position) {
alert("showPosition");
console.log("Latitude: " + position.coords.latitude + "<br>Longitude: " + position.coords.longitude);
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
$.ajax({
type: "POST",
url: '/Home/Coordinates',
data:
{
latitude: latitude,
longitude: longitude
},
success: function (data) {
$("#content").html(data);
},
error: function () {
alert("Error");
}
});
}
if (navigator.geolocation) {
alert("support geolocation");
navigator.geolocation.getCurrentPosition(showPosition,function(error) {
alert("error");
},
{ maximumAge: 12000000, timeout: 30000 });
}
else {
alert("not suported");
console.log("Geolocation is not supported by this browser.");
}
});
</script>
On Safari is it dows not call the showposition() function but it always end up in alert("error"). Does anyone knows why or what I'm doing wrong here ? Thanks.
(document).ready(function () { function showPosition(position) { alert("showPosition"); console.log("Latitude: " + position.coords.latitude + "<br>Longitude: " + position.coords.longitude); var latitude = position.coords.latitude; var longitude = position.coords.longitude;
.ajax({ type: "POST", url: '/Home/Coordinates', data: { latitude: latitude, longitude: longitude }, success: function (data) {
("#content").html(data); }, error: function () { alert("Error"); } }); } if (navigator.geolocation) { alert("support geolocation"); navigator.geolocation.getCurrentPosition(showPosition,function(error) { alert("error"); }, { maximumAge: 12000000, timeout: 30000 }); } else { alert("not suported"); console.log("Geolocation is not supported by this browser."); } }); </script>
On Safari is it dows not call the showposition() function but it always end up in alert("error"). Does anyone knows why or what I'm doing wrong here ? Thanks.
这篇关于Safari 5.1.7中的地理位置不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!