Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
172
rated 0 times [  179] [ 7]  / answers: 1 / hits: 138907  / 14 Years ago, fri, october 15, 2010, 12:00:00

How do you get Client location using Google Maps API v3? I tried the following code but kept getting the google.loader.ClientLocation is null or not an object error. Any ideas why ??



if (google.loader.ClientLocation) {
alert(google.loader.ClientLocation.latitude+ +google.loader.ClientLocation.longitude);
}


Thank You


More From » google-maps

 Answers
21

Try this :)



    <script type=text/javascript src=http://www.google.com/jsapi></script>
<script type=text/javascript>
function initialize() {
var loc = {};
var geocoder = new google.maps.Geocoder();
if(google.loader.ClientLocation) {
loc.lat = google.loader.ClientLocation.latitude;
loc.lng = google.loader.ClientLocation.longitude;

var latlng = new google.maps.LatLng(loc.lat, loc.lng);
geocoder.geocode({'latLng': latlng}, function(results, status) {
if(status == google.maps.GeocoderStatus.OK) {
alert(results[0]['formatted_address']);
};
});
}
}

google.load(maps, 3.x, {other_params: sensor=false, callback:initialize});

</script>

[#95314] Wednesday, October 13, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jenna

Total Points: 706
Total Questions: 107
Total Answers: 106

Location: Azerbaijan
Member since Tue, Sep 21, 2021
3 Years ago
;