diplaying latitude和longutude使用geolocation API的问题 [英] problem with diplaying latitude and longutude using geolocation API

查看:86
本文介绍了diplaying latitude和longutude使用geolocation API的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Modnizer地理位置api显示纬度和经度。

在我的java脚本代码中,当我尝试使用代码执行我的Web应用程序时。



  if (Modernizr.geolocation){
// 查找位置...填写。
// alert(在Modernizer中);
// 如果我使用if(Modernizr.geolocation)

navigator .geolocation
.getCurrentPosition(location_found, location_error);

}





按下设置位置按钮时没有任何反应。但是当我试图执行网络应用程序时没有



 如果( Modernizr.geolocation)
{
}





我得到网页上显示的纬度和经度。 y控件未从if(Modernizr.geolocation)语句传递。

解决方案

请参阅 https://modernizr.com/docs [ ^ ]



Quote:

地理位置API地理位置

检测支持地理位置API,供用户提供他们在Web应用程序中的位置。





如果浏览器不支持它或者在浏览器询问时选择阻止它将返回false。


我宁愿使用 HTML5 [ ^ ]地理定位功能。

< pre lang =Javascript> function getLocation(){
if navigator .geolocation){
navigator 。 geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = 此浏览器不支持地理位置。;
}
}
function showPosition(position){
alert( 纬度: + position.coords.latitude +
,经度: + position.coords.longitude);
}





-KR


I am trying to display latitude and longitude using Modnizer geolocation api.
In my java script code when i try to execute my web application with the code.

if (Modernizr.geolocation ) {
    // Find location... fill in.
    //alert(" inside Modernizer");
    // Not coming here if i use if(Modernizr.geolocation)

     navigator.geolocation
    .getCurrentPosition(location_found, location_error);

}



Nothing happens when i press the set location button. but when i try to execute the web application without

if (Modernizr.geolocation )
{
}



I get the latitude and longitude displayed on the web page. y the control is not passing from the if (Modernizr.geolocation ) statement .

解决方案

See https://modernizr.com/docs[^]

Quote:

Geolocation API geolocation
Detects support for the Geolocation API for users to provide their location to web applications.



If the browser does not support it or if you choose block when asked by the browser it will return false.


I'd rather use HTML5 [^] feature of geolocation.

function getLocation() {
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(showPosition);
    } else {
        x.innerHTML = "Geolocation is not supported by this browser.";
    }
}
function showPosition(position) {
    alert("Latitude: " + position.coords.latitude + 
    ", Longitude: " + position.coords.longitude); 
}



-KR


这篇关于diplaying latitude和longutude使用geolocation API的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆