is there a good PHP geolocation service? [closed]

Geo-location would need to be done in the browser, since the server (ie PHP) would never get to find out most of the relevant data. The main API for doing geolocation in the browser is Google’s, but you as a developer wouldn’t need to use that API; you’d use the browser’s API, which is standardised (though only supported in a few browsers so far).

The most useful information you’ll get for locating a user at the server end would be their IP address, which is often sufficient to locate them down to the nearest town. There are IP-to-nation and IP-to-location databases and APIs which you can download to help with this. Some are free, but to get the town-level locations, you’ll be paying for the service. Whichever you go with, they do need to be kept up-to-date though, because IP ranges are often re-allocated.

The browser-level APIs work by having the browser scan the area for Wi-Fi access points. It sends the list of access points to Google, who then use that to work out the Lat/Long (often with alarmingly accurate results).

How do they do that? You may remember Google getting into trouble recently for sucking data from people’s Wi-Fis? What they were actually trying to do was map the world’s Wi-Fi access points for this geolocation feature.

It does, of course, require the client to have Wi-Fi enabled.

Note that your browser doesn’t give direct access to this list of access points to the client (ie Javascript or the DOM), so you can’t post it to PHP to get the location using this method via the server; it would have to be done at the client-end.

Leave a Comment