0

I'm trying to set up client location detection for my mobile web site using the code below:

<html>
   <head>
   </head>
   <body>
      <script type="text/javascript" src="http://www.google.com/jsapi"></script>
      <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&libraries=geometry"></script>
      <script>
         var geocoder = new google.maps.Geocoder();
         var loc = {};
         if(google.loader.ClientLocation) {
         loc.lat = google.loader.ClientLocation.latitude;
         loc.lng = google.loader.ClientLocation.longitude;
         }
         var clientLocation = new google.maps.LatLng(loc.lat, loc.lng);
         alert(clientLocation);
      </script>
   </body>
</html>

This works fine on Safari on my desktop by returns (NaN,NaN) when I run it on the Safari mobile browser. Can anyone suggest what might be going wrong?

Ben Pearce
  • 6,884
  • 18
  • 70
  • 127
  • May I guess that your desktop and your iPhone didn't share the same IP? ClientLocation is IP-based, there is no guarantee that any IP may be resolved. Take a look at http://stackoverflow.com/questions/14195837/is-google-loader-clientlocation-still-supported – Dr.Molle Aug 19 '13 at 23:50

1 Answers1

0

I believe the above code works.

I just tested this on my iPhone 5 using Safari, and it works okay.

Are you sure that you have location services enabled on your iPhone for Safari? Make sure you haven't turned them off.

Charlie74
  • 2,883
  • 15
  • 23
  • Hmmm. It turns out I did have location services off for Safari, but now I've turned it on, cleared my cache, restarted my iphone 5 and I'm still getting (NaN,NaN). – Ben Pearce Aug 19 '13 at 23:27
  • Odd, huh? I refreshed my page a dozen times or so... seems to work every time. I also tried on my mobile Chrome browser. Works okay there too. I'm stumped! – Charlie74 Aug 19 '13 at 23:31
  • Out of curiosity... does it work for you if you hit my test page? http://www.charlessamet.com/test.html – Charlie74 Aug 19 '13 at 23:32
  • Maybe it takes a little while for ATT's satellite to find me – Ben Pearce Aug 19 '13 at 23:33