javascript - How can we get visitor location using google API -



javascript - How can we get visitor location using google API -

<script type="text/javascript" src="http://www.google.com/jsapi?key=api key"></script> if(google.loader.clientlocation) { visitor_lat = google.loader.clientlocation.latitude; visitor_lon = google.loader.clientlocation.longitude; visitor_city = google.loader.clientlocation.address.city; visitor_region = google.loader.clientlocation.address.region; visitor_country = google.loader.clientlocation.address.country; visitor_countrycode = google.loader.clientlocation.address.country_code; document.getelementbyid('yourinfo').innerhtml = visitor_lat; } else { // implemented maxmind method (see source code) or may want leave message: document.getelementbyid('yourinfo').innerhtml = '<p>whoops couldnt find you!</p>'; }

i used code finding current location of each visitor .but google.loader.clientlocation returns null value.is there other way find location of visitor.please help me.

try this: html5 - using geolocation

<!doctype html> <html> <body> <p id="demo">click button coordinates:</p> <button onclick="getlocation()">try it</button> <script> var x = document.getelementbyid("demo"); function getlocation() { if (navigator.geolocation) { navigator.geolocation.getcurrentposition(showposition); } else { x.innerhtml = "geolocation not supported browser."; } } function showposition(position) { x.innerhtml="latitude: " + position.coords.latitude + "<br>longitude: " + position.coords.longitude; }

javascript google-maps-api-3

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -