unexpected problem with google.loader.ClientLocation

698 views
Skip to first unread message

Emmanuel Jacquart

unread,
Sep 30, 2010, 8:06:06 AM9/30/10
to Google AJAX APIs
I have a problem using the google AJAX API on my website. I wrote a
code that worked till yesterday. I don't understand why it doesn't
work anymore. I just use the google.loader.ClientLocation and my debug
shows me that this variable is always null.
Here is an extract of my code (I checked the google.loader that is
charged, my key is valid and recognized) :
<script type="text/javascript" src="http://www.google.com/jsapi?
key=MY_KEY"></script>
<script language="Javascript" type="text/javascript">
jQuery(document).ready(function () {

if(google.loader.ClientLocation)
{
visitor_country =
google.loader.ClientLocation.address.country;
...

Have you any idea about this problem?

Jeremy Geerdes

unread,
Sep 30, 2010, 8:52:06 AM9/30/10
to google-ajax...@googlegroups.com
google.loader.ClientLocation returns null when Google is unable to geocode your IP address. Since this is a very inexact science due to the dynamic nature of the vast majority of IP addresses on the planet, the ClientLocation functionality should not be relied on for mission-critical applications. Rather than depending on it, I would suggest checking first for navigator.geolocation and then, since you're looking for the country, reverse geocoding the coordinates via the GMaps' geocoding service.

Jeremy R. Geerdes
Effective website design & development
Des Moines, IA

For more information or a project quote:
http://jgeerdes.home.mchsi.com
jrge...@gmail.com

If you're in the Des Moines, IA, area, check out Debra Heights Wesleyan Church!

> --
> You received this message because you are subscribed to the Google Groups "Google AJAX APIs" group.
> To post to this group, send email to google-ajax...@googlegroups.com.
> To unsubscribe from this group, send email to google-ajax-searc...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/google-ajax-search-api?hl=en.
>

Emmanuel Jacquart

unread,
Sep 30, 2010, 10:51:15 AM9/30/10
to Google AJAX APIs
Thank you for the response, I'd just like to keep my code because it
worked last week but I changed nothing before the problems arrives. I
checked with differents computers, with differents IPs address and
configuration (with or without proxy). Can we explain that the API
doesn't answer anymore? Could someone confirm me that
google.loader.ClientLocation still works fine?

Jeremy Geerdes

unread,
Sep 30, 2010, 10:53:00 AM9/30/10
to google-ajax...@googlegroups.com
The ClientLocation feature worked great for me for a long time, but then stopped months ago. Since then, there have been a couple of times when it worked, but it is highly unreliable.

Jeremy R. Geerdes
Effective website design & development
Des Moines, IA

For more information or a project quote:
http://jgeerdes.home.mchsi.com
jrge...@gmail.com

If you're in the Des Moines, IA, area, check out Debra Heights Wesleyan Church!

Emmanuel Jacquart

unread,
Sep 30, 2010, 11:10:20 AM9/30/10
to Google AJAX APIs
Thank you another time for the precisions. I didn't know that this
feature was so unreliable.

Jeremy Geerdes

unread,
Sep 30, 2010, 11:24:30 AM9/30/10
to google-ajax...@googlegroups.com
Yeah, it's one of those things the Googlers don't exactly advertise :) Since you mentioned that you would like to keep your existing code, you could check for the availability of ClientLocation and, if it's not there, use the navigator.geolocation functionality of modern browsers as I described in my previous post.

Jeremy R. Geerdes
Effective website design & development
Des Moines, IA

For more information or a project quote:
http://jgeerdes.home.mchsi.com
jrge...@gmail.com

If you're in the Des Moines, IA, area, check out Debra Heights Wesleyan Church!

On Sep 30, 2010, at 10:10 AM, Emmanuel Jacquart wrote:

> Thank you another time for the precisions. I didn't know that this
> feature was so unreliable.
>

omr

unread,
Sep 30, 2010, 6:36:12 PM9/30/10
to Google AJAX APIs
This documentation may be of interest:

http://code.google.com/apis/maps/documentation/javascript/basics.html#DetectingUserLocation

Quoted from that documentation:

> "... As a user's IP address can only provide a rough estimate of a user's location, we don't recommend using this approach for geolocation. The W3C approach is the easiest and most fully-supported so it should be prioritized over other methods. ..."

See the code sample given there.
See also this complete and revised version of that sample:

http://code.google.com/apis/maps/documentation/javascript/examples/map-geolocation.html

See also this alternative sample:

http://gmaps-samples-v3.googlecode.com/svn/trunk/geolocate/geolocate.html

-- omr
Reply all
Reply to author
Forward
0 new messages