Is google.loader.clientlocation still supported
It seems this API is kind of "deprecated" although it still works for some IPs.
This is the answer I got from here:
- http://code.google.com/p/google-ajax-apis/issues/detail?id=586
The geolocation functionality in the Loader hasn't been retired, per se. We stopped documenting it several years ago and have recommended the HTML-based solutions due to their improved accuracy, but the functionality itself has not been removed from the Loader at this time. Thanks!
So when location is not found for IP, google.loader.ClientLocation is null
Getting user location with google.loader.ClientLocation working for me but not others
Google ClientLocation uses IP address geolocation. There are several IP address geolocation providers out there (the related questions in the sidebar on the right will give you several of those) and they give different results to different users. Google ClientLocation won't be able to locate everyone and it won't always give answers that are as precise or as accurate as some competitors.
On my test page, for example, I use Google ClientLocation and IPInfoDB and Google ClientLocation doesn't find me at home right now, while IPInfoDB thinks I'm in Sunnyvale instead of Berkeley. You may find that one provider is better than the others (particularly if you pay for its database), but I suspect that the most robust method, if you really need it, is to use several and hope that at least one will have a result. You should know up front that IP geolocation will not always work for all users (those behind an anonymizing proxy, for example, will never be located this way).
Also, if you want a more precise location, you can use a Javascript API to ask the browser for the user's exact location. On supported browsers the user will receive a small pop-up asking for their permission and, if given, the browser will then use GPS (Mobile Safari on the iPhone, for example) or WiFi triangulation (Firefox 3.5+) to determine latitude and longitude. You can see how this works on my test page, and compare it with IP geolocation. Not all browsers support the W3C Geolocation API, but a growing number do.
How to get Client location using Google Maps API v3?
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>
Related Topics
HTML Table Different Number of Columns in Different Rows
How to Change the Font-Size of an <Option> Element Within <Select>
How Remove Border Around Image in CSS
Some Elements Missing While Downloading from Httpwebrequest
Aligning Elements in Last Flexbox Row
How to Avoid Wrapping in CSS Float
Bootstrap 4 - Fullscreen Mobile Navbar
Print Table Footer at the Very Bottom on Last Page
Unwanted Auto-Scrolling to Top on Input Focus, with Safari
Table Row Won't Contain Elements with Position:Absolute
Bootstrap Grid, Do I Need a Container
CSS - Hide Options from Select Menu on iPhone & Safari
How to Open Submenu on Hover of Main Menu
Put Icon Inside Input Element in a Form (Not as Background Image!)