javascript - How to get current position(city,state,zipcode) in safari browser ? -
i have tried below code work chrom,firefox browser not work on safari browser on desktop(wired connection) , not work in windows phone(tested on nokia lumia 625.) work on ipad,iphone (through wifi) safari browser.
please give me solution issue.
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"> </script>
in header call function on load page.
$(document).ready(function() { requestposition(); });
write function in js file
function requestposition() { if (typeof navigator.geolocation == "undefined") { alert("your browser doesn't support geolocation api"); return; } navigator.geolocation.getcurrentposition(function(position){ var geocoder = new google.maps.geocoder(); geocoder.geocode({ "location": new google.maps.latlng(position.coords.latitude,position.coords.longitude) }, function (results, status) { if (status == google.maps.geocoderstatus.ok) { j = 0; (var = 0; < results[j].address_components.length; i++) { if (results[j].address_components[i].types[0] == "locality") { //this object looking city = results[j].address_components[i]; } if (results[j].address_components[i].types[0] == "administrative_area_level_1") { //this object looking region = results[j].address_components[i]; } if (results[j].address_components[i].types[0] == "country") { //this object looking country = results[j].address_components[i]; } } city=city.long_name; state=region.long_name; country=country.long_name; $("#_state").val(state); $("#_country").val(country); $("#_city").val(city); } else alert("unable retrieve address"); }); }, function (positionerror) { alert("error: " + positionerror.message); }, { enablehighaccuracy: true, timeout: 10 * 1000 // 10 seconds } }
safari geolocation works when connected wifi. when connected wired connection safari calls error callback geolocation functions.
Comments
Post a Comment