Google Maps geo-location by IP Flex example

Following on from my earlier post regarding Google Maps and Flex, I’ve put together a new example which I reckon’s pretty nifty.

Somehow my idea was spawned by Andrew Shorten’s post which discussed using Google Maps and the new Adobe Cocomo service to create a collaborative mapping application. And I say somehow, as I’m not really sure how I went off on the tangent of geo-locating IP addresses when the original post was about two users drawing stuff on a shared map! Maybe they can see where each other is on the map and start drawing a line until they meet somewhere in the middle…

Anyway, (il)logic aside here’s the example I whipped up:

View source is enabled in the following example.

The “Geo-locate IP address” text field should auto populate with your current IP address. The initial map will load and center on London.

When coding up the infowindow that displays, I found this reference on the Google site very useful – http://code.google.com/apis/maps/documentation/flash/reference.html

The actual information is coming from a whopping great big file that I’ve uploaded to my server which was supplied by Maxmind. There’s a few other databases that they supply, so I might add some more features to this example down the track. And they have pay for use and free versions of all their data, which is great!

Be Sociable, Share!
Tagged with: , , , ,
Posted in Flex

15 comments on “Google Maps geo-location by IP Flex example
  1. Abdul Qabiz says:

    pretty cool, thanks for sharing the code.

    -abdul

  2. Peter says:

    Awesome stuff. Do you have the xml code for viewing?

  3. @Peter – which xml code are you after? If you’re looking for the MXML code, then just right click on the Flash and “View Source”

  4. Peter says:

    I figured it out – DUH! :) but thanks for your help.

  5. Hey,
    Here is a tutorial to show how to install and use the MaxMind Database with PHP scripts examples. And it also shows how to display it on a map (Yahoo! Map) (french):
    http://www.flex-tutorial.fr/2009/02/01/flex-yahoo-maps-api-geo-localisation-par-ip-dun-visiteur-exemple/

  6. jfdonohoe says:

    This is great. The map showed my actual location within yards!

    Question for you about accuracy. Do you know of any resources that shows the reliability of current geolocation IP detection experiences.

    I would like to be able to assure my clients that accurately identifying an end-users geolocation by IP address to the metro, or even state, level is above 90% accurate.

    It would be great if there was some sort of public accessible statistics I could direct them to.

    I know the service/database used has a lot to do with the final accuracy results but a 99.9% accurate database still is only one piece of the puzzle for a consistently reliable end-user experience.

    Thanks!

    -john

  7. Hi John, you’d have to take this up with Maxmind (http://www.maxmind.com/app/city#api) who created the database.

  8. Kiran says:

    Wonderful , I don’t know how you are getting this exact data ? I know you said maxmind . I tried maxmind for one IP ( Location India, City :- Hyderabad) it gave me wrong result . In fact I tried most of the IP geolocater and every one is giving the wrong City name.But when I tried with you search It gave me the exact right result . I tried several more IP address with your site and it gave the correct result .
    Can we use you URL
    http://blog.wrench.com.au/wp-content/uploads/2008/12/geoip/sample_city.php
    for our website :)

    Regards
    Kiran

  9. @Kiran – what’s the link to your site?

    That PHP file can be downloaded from the MaxMind website here – http://geolite.maxmind.com/download/geoip/api/php/

  10. Kiran says:

    Thanks Jason for the information . My website still not live . I am planing it for next month . It is kind of community website .

    I downloaded the PHP files and downloaded geolite database and tried it . But still location is showing wrong . Are you using full version of it?

    I don’t want to give the IP address here for security reasons . If you have any junk email id , I can send you the IP address.

    Regards
    Kiran

  11. Kyriacos Antoniades says:

    Dear Jason,

    Please, please, please can you send me the:

    http://blog.wrench.com.au/wp-content/uploads/2008/12/geoip/sample_city.php

    file.
    This is the only thing that would make your example to work on mine!!!

    Thanking you in anticipation.

    Regards,

    Kyriacos

  12. That code’s from the geolite example I linked to in the 9th comment above, but here’s the code anyway:

    < ?php

    // This code demonstrates how to lookup the country, region, city,
    // postal code, latitude, and longitude by IP Address.
    // It is designed to work with GeoIP/GeoLite City

    // Note that you must download the New Format of GeoIP City (GEO-133).
    // The old format (GEO-132) will not work.

    include("geoipcity.inc");
    include("geoipregionvars.php");

    // uncomment for Shared Memory support
    // geoip_load_shared_mem("/var/www/vhosts/blog.wrench.com.au/httpdocs/wp-content/uploads/2008/12/geoip/GeoLiteCity.dat");
    // $gi = geoip_open("/var/www/vhosts/blog.wrench.com.au/httpdocs/wp-content/uploads/2008/12/geoip/GeoLiteCity.dat",GEOIP_SHARED_MEMORY);

    $gi = geoip_open("/var/www/vhosts/blog.wrench.com.au/httpdocs/wp-content/uploads/2008/12/geoip/GeoLiteCity.dat",GEOIP_STANDARD);

    $record = geoip_record_by_addr($gi,$_POST['ip']);
    //print $record->country_code . ” ” . $record->country_code3 . ” ” . $record->country_name . “n”;
    //print $record->region . ” ” . $GEOIP_REGION_NAME[$record->country_code][$record->region] . “n”;
    //print $record->city . “n”;
    //print $record->postal_code . “n”;
    //print $record->latitude . “n”;
    //print $record->longitude . “n”;
    //print $record->dma_code . “n”;
    //print $record->area_code . “n”;
    print “latitude=”.$record->latitude.”&longitude=”.$record->longitude.”&city=”.$record->city.”&country=”.$record->country_name;
    geoip_close($gi);

    ?>

4 Pings/Trackbacks for "Google Maps geo-location by IP Flex example"
  1. [...] Vote Google Maps geo-location by IP Flex example [...]

  2. [...] Google Maps geo-location by IP Flex example at calm in the chaos [...]

  3. [...] Google Maps geo-location by IP Flex example at calm in the chaos [...]

  4. [...] Google Maps geo-location by IP Flex example at calm in the chaos [...]

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Posts this month
December 2008
M T W T F S S
« Nov   Jan »
1234567
891011121314
15161718192021
22232425262728
293031  
Archives