我在移动网站上遇到地理定位问题。在iPhone上与safari工作正常。在带有Chrome浏览器的Android上不能正常工作(但是mozilla一切都很好)。我认为这个问题与HTTP有关(使用HTTPS进行chrome地理定位工作)
var get_location = function(change_location) {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position){
var lat = position.coords.latitude;
var lng = position.coords.longitude;
var latlng = new google.maps.LatLng(lat, lng);
var location = {};
geocoder.geocode({'latLng': latlng}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if(results.length > 0) {
for(var i = 0; i < results[2].address_components.length - 1; i++) {
switch(results[2].address_components[i].types[0]) {
case "locality":
location.city = results[2].address_components[i].long_name;
break;
case "administrative_area_level_1":
location.region = results[2].address_components[i].long_name;
break;
case "country":
location.country = results[2].address_components[i].long_name;
break;
}
}
change_location(location);
} else {
console.log('No location found');
}
}
});
});
} else {
console.log('No GPS');
}
}