IOS10 Window.navigator.geolocation.getCurrentPosition can't locate the problem

Source: Internet
Author: User

In iOS 10, Apple has modified the WebKit location permission, and all location-requested pages must be HTTPS protocol.

If a non-HTTPS Web page, the HTTP protocol through the HTML5 native location interface will return an error, that is, unable to properly navigate to the user's specific location, and the Web site that has supported HTTPS will not be affected.

The solutions currently available:

1. Set HTTP for the website to HTTPS.

2, through the third-party API solution.

By the way the location method is attached:

//// positioning method One
$ (function () {
Startgps ();
});
//Get Geolocation method
function Startgps ()
{
//Determine if support is supported
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition (showgps,//success callback function
function (Error)//failure callback
{
Getpositionerror (error);
},
{enablehighacuracy:true, timeout:5000,maximumage:0}); This sets the timeout to 5000 milliseconds, or 1 seconds.
}
Else
{
document.getElementById (' Geo_loc '). innerhtml= "Your browser does not support map positioning";

}
}
function Showgps (position)
{
document.getElementById (' longitude '). Innerhtml= "Longitude" +position.coords.longitude+ "latitude" +position.coords.latitu De;
getaddress (position.coords.latitude,position.coords.longitude);

}
function Getpositionerror (error) {
switch (error.code) {

Case error. TIMEOUT:

alert ("Connection timed out, please retry");

Break ;

Case error. Permission_denied:

alert ("You refused to use Location sharing service, query cancelled");

Break ;

Case error. Position_unavailable:

alert ("Dear Mars netizen, very sorry, we are temporarily unable to provide location services for your planet");

Break ;

}
}



//Positioning method two
if (navigator.geolocation) {
Navigator.geolocation.getCurrentPosition (
function (position) {
document.getElementById (' longitude '). Innerhtml= "Longitude" +position.coords.longitude+ "latitude" +position.coord S.latitude;
document.getElementById (' accuracy '). Innerhtml= "Error" +position.coords.accuracy+ "M";
getaddress (position.coords.latitude,position.coords.longitude);
},
function (Error) {
var errorType = [' You refuse to share location information ', ' Get location information ', ' Get location information timed out '];
//alert (errortype[error.code-1]);
document.getElementById (' Geo_loc '). innerhtml=error.code+ "\ n" +error.message;
document.getElementById (' Geo_loc '). innerhtml= errortype[error.code-1];
}
);
}else{
document.getElementById (' Geo_loc '). innerhtml= "Your browser does not support map positioning";
}

function GetAddress (latitude,longitude) {
var Geocoder;
var map = new Amap.map ("container", {
Resizeenable:true,
zoom:18
})
var lnglatxy = [longitude,latitude];//the coordinates to be converted to address description
//Loading geocoding plugins
var Geocoder;
Amap.service (["Amap.geocoder"], function () {
Geocoder = new Amap.geocoder ({
radius:1000,
extensions: "All"
});
//Inverse geo-coding
geocoder.getaddress (Lnglatxy, function (status, result) {
//Retrieving Inverse geocoding results
if (status = = = ' complete ' && result.info = = = ' OK ') {
geocoder_callback (result);
}
});
});
}
function Geocoder_callback (data) {
var address = data.regeocode.formattedAddress;//Return addresses description
document.getElementById ("result"). InnerHTML = Address;
}

IOS10 Window.navigator.geolocation.getCurrentPosition cannot locate the problem

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.