Geolocation using PHP or HTML 5 location services?

Posted on 2011-05-05
Last Modified: 2012-05-11
I need to implement geolocation in a PHP-based app that I'm developing, and I'd like to know what the best way to go about it is.  

Based on what I've researched so far, .. doing a lookup based on IP address (using an API) is not always 100% accurate, .. and some lookup service providers are more reliable than others. Also, .. you're generally only able to identify the Country of the visitor, .. and not the precise location (ie: US State / City).  So .. I'm wondering if there might be a better way?

Does anyone here have any suggestions as to what the best way to implement something like this would be?  I'm looking for the most accurate and precise geolocation method possible (preferably something that identifies more than just the Country), .. and if it means that we have to subscribe to and pay for some service, .. that's ok.  

What about HTML 5's location services?  Is  there any way that I can leverage that?  

Any tips or advice (or code samples) would be greatly appreciated.

- Yvan

Question by:egoselfaxis
    LVL 107

    Expert Comment

    by:Ray Paseur
    Have not used HTML5.  I have used GEOIO with great success.  Free for low-level use, modest charge for high-level use.  Example of a map drawn from a data base of GEOIO responses is here:

    In that map I intentionally limit the geocode information to DECIMAL(8,4) with a UNIQUE index on lat, lon columns to keep the map from becoming cluttered.  Greater accuracy - right to the rooftop - is achieved with DECIMAL(10,6).

    GEOIO is here.  Get an API key and you can start testing within seconds.

    In my app I decoupled the GEOIO part from the rest of the web site.  I get the client's IP address and POST a script that uses GEOIO information to update my data base.  I do not wait for the POST to complete and I do not care if the GEOIO service fails or rejects my request.  YMMV on this point!
    LVL 12

    Accepted Solution

    This artical is helpful:

    You might also consider subscribing with a company that provide this service so you can get the updates.
    LVL 30

    Assisted Solution

    by:Marco Gasi
    You can find simple free service here: Once you are registered, you get a free key to use in very simple code

    For city:<your_api_key>&ip=

    For country:<your_api_key>&ip=

    Here you find a little script to get data and echo them ina page.


    Author Comment

    Thanks guys!  This is exactly what I was looking for.

    - Yvan

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Javascript: Crash Course

    Javascript is not only emerging as the most important language to know, it's flexibility is unique. With Javascript being deployed on the web, mobile and even the desktop this is the one language that all technologists need to know.

    Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
    Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
    In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
    The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now