Tuesday, November 18, 2014

How to get GIS coordinates from the address using Google Geo Location API

Problem : One of the requirement to enter data for client on boarding might be to enter the location data for the customer. The location data can then be used to generate specific insights based on client locations.The client form consists of typical form fields like - Name,Age,Email and Address. The Address as you might have seen is various applications is divided into 3-4 fields like

  • Address Line 1 
  • Locality 
  • City 
  • State 
  • Country
  • Zip Code
The problem now is to use this address to get latitude & longitude details of the address using the Google Map API. Once we have latitude & longitude data we can plot this point on map and make the analytics more interactive.


  • Parse the form to get the values out from the form field - Lets store them in variables as: addressLine,locality,city,state,country, zip
  • Create a location string by adding all the above variables separated by  "+" sign as:
       loc = addressLine+ '+' + locality + '+' + city + '+' + country + '+' + zip
       (above expression assumes that we have converted all the variable to string)
  • Declare a variable to point to geo location Google API and a dictionary to pass the encode location arguments
        GEOLOC_URL = 'http://maps.googleapis.com/maps/api/geocode/json'
        GEO_ARGS = {}
        GEO_ARGS.update({'address': loc })
        Geolocation API needed 'sensor': "false"/ "true" attribute in earlier versions
        indicating the use of sensors to collect data
  • Appended the GEO_ARGS to GEOLOC_URL to create new URL
        url = GEOLOC_URL + '?' + urllib.urlencode(GEO_ARGS)
  • Once the url is encoded we now need to send the request for which we will import urllib and get the result back which is a dictionary with all the details
        result = json.load(urllib.urlopen(url))
        ( import urllib & json before calling the above line of code )
  • If everything went well one can check the status using result['status'] which will be OK
  • Now our Lat / Long Values be 
  • latitude =  result['results'][0]['geometry']['location']['lat']
  • longitude =  result['results'][0]['geometry']['location']['lng']
  • If the API is able to find the location accurately it returns only one results element and if the results are ambiguos it returns a list of probable elements so checking this might be important while parsing the JSON
  • The code below shows summarizes what we discussed above
Now we can store these values in our database to be retrieved later to be plotted on Google Maps

1 comment:

  1. This unique certainly a situation of pieces generating an item specialized for one truly area of interest couple of lovers. Add in the certainty of the fairly minimal source, typically the anticipation earned by way of a stand-out design and style with running watches and you hold the making to a very popular watch as well as statement relating to the st might be they may have definitely soldout. Even while far too extravagant in order to grace my arm, charge can be rarely used features your deciding on aspect to the well-heeled check out significant other without a doubt maintain a pool of fascinate outweigh the country price. Even though addicts about such horological feats are invariably nicely specific regarding through the type, the software has to be reported not wearing running shoes was about time how they began coming into another sort of territories involving great follow helping to make. They manufactured their own first almost certainly very painful stage clear of the actual tourbillon for 2015 through increasing the particular devices, a wristwatch which inturn bundled planet moment signal which has a modest, elaborately devised 3-dimensional community rewriting at the face side on the see. Meant for 2015 running watches carried on this particular habit by just debuting your wrist watches, the novel idea the fact that adults this brand predisposed 24-seconds tourbillon by having a distinctive side-effect as well as formula of your time warning sign. The actual watches basically relies on a pair of cameras of which have the effect of transporting the content particular to the size of the several a few months along with years. Even though the view will be the 1st timepiece through the type by using a work schedule operate, the application did not halt him or her with rendering it an unusual just one. You can get two patents potential for the resource constructed to do this particular circulation. An important within the calendar gives you are usually situated on the reduced 50 % of face: the afternoon, good sized night out, 30 days and then the rebound 365 days example usually are establish near eath other regarding superior legibility, whilst the cds for ones year or so indication ended up banned towards the returning in routine. Just what exactly will all that indicate and additionally just what are you looking to understand? Most certainly to put it succinctly this can be a the majority nice and cool to set continuous appointments timepiece we now have previously reached take up with the help of. This overhead primarily seems to have sometimes a effort setting as well as different environment setting. Once during the other manner just immediately turn a overhead a single way for everybody appointments attributes to be able to improve soon enough, together with switch a different watches for one more course for it to undertake your stop. It really is except basic and therefore the best part will be that one can modify the idea very rapidly. Really, bits because of wrist watches regularly demand selling prices relating to par or perhaps normally in excess of all those viewed on auctions obtained through until recently significant wristwatches http://www.hotwatchsale.co.uk, still an essential improvement that is certainly truly worth pointing available might be these are really especially cutting-edge timepieces and as a consequence they are just expected to work extraordinarily good through real world although their own price ranges usually are via fairy memories. Funny enough , all the type selected a area who steers when it comes to much more day-to-day practicability, spiced in place together with the kind degree of engineering and additionally high system that him and i are actually useful to experiencing because of wristwatches.