
Ask HN: What do you use for Geocoding? - ColinWright
I find I have a requirement to take a description, such as one would feed to Google, and convert it to Lat&#x2F;Long.  It need not be particularly accurate, a few miles is good enough.  Given the wide range of interests and experience here on HN, I thought I&#x27;d ask if anyone here has done this, what they&#x27;ve used, and how well it worked.<p>So for example, given &quot;Lady Lever Art Gallery&quot; it could produce something like &quot;53.35,-3.00&quot; and that would be good enough.  Or given something like &quot;Golden Gate Bridge&quot; it could return &quot;37.81,-122.48&quot;<p>Does anyone here do this?  What do you use?<p>Currently this is for personal use, and would be limited to at most a few requests per week.  I can use Google by hand, but if the project takes off then usage would increase, would need to be automated, and I would, of course, be willing to pay for an appropriate service.<p>Suggestions and comments welcome, especially descriptions of what you currently use, and your experience with it&#x2F;them.<p>TIA.
======
samlevy
I've been looking at the CloudMade Geocoding API for a side project and they
return good results in the UK. The POI search might also be helpful but I
haven't tried it yet.

You get 100k free requests per month and then it's $15 per 100k.

Their APIs are licensed under the Creative Commons Attribution 2.0 License.

[http://cloudmade.com/products/geocoding](http://cloudmade.com/products/geocoding)

[http://developers.cloudmade.com/projects/show/geocoding-
http...](http://developers.cloudmade.com/projects/show/geocoding-http-api)

[http://cloudmade.com/api-terms-of-service](http://cloudmade.com/api-terms-of-
service)

~~~
ColinWright
So I've registered with CloudMade. That was painless.

Then ...

It appears with CloudMade that to get an API key I have to pretend I'm
building an APP, and have to have a web site describing my awesome new
product. Then when I try to ask a question, I get all the way through the
tedious process of constructing my question in their model of how a customer
should behave, only to have to login with a completely different account!
Google, Facebook, GetSatisfaction, something, but not the account I just
registered with them.

WTF?!?

~~~
samlevy
It is a bit rubbish but not as bad as other APIs I've had to register for (API
keys pending review/approval for several days). I just filled in the bare
minimum of App name and google.com for the App URL. Where are you trying to
ask questions? I've been using their support email address.

~~~
ColinWright
I tried clicking on the "Feedback" link on the left. When that didn't work,
I've tried sending them email to their support address.

In the meantime I've factored out and lifted _all_ the GeoCoding from my
application and added my own internal "API", so whatever service I end up
using, I can switch fairly easily to another when necessary.

------
cinquemb
I have done something similar with with a python script that basically:

\- parsed locations from an html file and stored them in a list

\- parsed them into this url:
'[https://maps.google.com/maps?q=%s'](https://maps.google.com/maps?q=%s') %
(location)

-parsed the html for an address

-parsed the address into this url: '[https://maps.google.com/maps/api/geocode/json?address=%s&sen...](https://maps.google.com/maps/api/geocode/json?address=%s&sensor=false') % (address)

-parse the coordinates

I used it to get oil refineries in the united states and it worked pretty
well… i can put it on github if you would like.

It probably can also be done between the front-end and back-end with a little
bit of trickery (the calls to google on the front-end, POST'ed html processing
on the back from the front-end), so that users ip is using the service and not
the servers.

~~~
ColinWright
That's very similar to what I've been doing so far, but it's broken again, so
I'm looking for something less fragile and more "official" so I can stop
having to fix it every few months, or every few weeks. I'll probably fix it
this time while I'm searching for something more robust.

Thanks.

~~~
cinquemb
Good luck with your search, everything seems so fractured when it comes to
doing things like this.

I'm curious, how does your method break? Is it the query string not finding
any results to a location, wrong locations, or something else?

~~~
ColinWright
I've been sending query to:

    
    
        'https://maps.google.com/maps?q=%s' % sanitise(location)
    

and then parsing the result to find the lat/lng. However, this isn't an
"official" way of doing it, and the format of the html has changed. The result
used to match this:

    
    
        'viewport_center_lat=([-0-9.]*);var viewport_center_lng=([-0-9.]*)'
    

but now it looks like this:

    
    
        'latlng:{lat:([-0-9.]*),lng:([-0-9.]*)}'
    

Yes, I'm using regexs to parse HTML.

However, now that's working again, but I might switch to the explicit two
phase process used in
[https://news.ycombinator.com/item?id=6058751](https://news.ycombinator.com/item?id=6058751)
\- or I might directly use the second link mentioned there, instead of calling
the URL I currently use.

Does that all make sense?

~~~
cinquemb
Yeah it makes sense.

If you are getting locations in specific, then it makes more sense to just use
the second url as you state.

I've been using BeautifulSoup, then searching for the span tags where the
"class" attribute is set to "pp-headline-item pp-headline-address", and
getting the formatted address of the possible locations that show up and using
that in the query to the second url (I'm lazy so I only get the first result
if multiple exist).

I don't know if that would work better than regexs because google could still
change the html every so often (but maybe not as often as javascript).

------
ig1
Two other options are the OpenStreetMap Geocoder (it's called Nominatim) and
the FourSquare API.

~~~
ColinWright
Thanks - will investigate. Currently having a nightmare trying to find a
registration service that actually works, and getting tired of creating new
passwords for every login.

------
wikwocket
Nokia HERE map/geocoding UI. Lots of features, good developer documentation.

~~~
ColinWright
Thanks for that, but in truth, I don't want lots of features - I want to send
a piece of text to a URI and get back a string from which I can pick out the
lat/long.

And you've given me no indication of how to find what you're recommending,
apart simply from searching for the text "Nokia here map/geocoding". Is that
what I should do to find it?

 _Added in edit ..._

So now I've done that search and found a description. Based on your
recommendation I decided to try it, so I clicked on the link on how to get my
API credentials, and I got this:

    
    
        404 Not Found
    
            Code: NoSuchKey
            Message: The specified key does not exist.
            Key: docs/maps_js/topics/credentials.html
            RequestId: 92390AF64837E443
            HostId: <omitted>
    
        An Error Occurred While Attempting to Retrieve a Custom Error Document
    
            Code: NoSuchKey
            Message: The specified key does not exist.
            Key: /error.html
    

This seems typical - things just don't work.

~~~
wikwocket
Sorry, I don't have my code/notes with me, but I wanted to put the link out
there. Nokia has tons of developer resources so it can be hard to find what
you need.

I will try to remember to post more later, but for now here is a basic
geocoding example: [http://developer.nokia.com/Community/Wiki/HERE_Maps_API_-
_Us...](http://developer.nokia.com/Community/Wiki/HERE_Maps_API_-
_Using_the_geocoding_service)

~~~
ColinWright
Sorry I'm so grumpy, but I'm getting various suggestions from various places,
and my experiences are, to say the least, unhappy ones. This is a typical
example. All looks well, then you follow a link to start using it, and you get
a 404, or an access denied, or some other message that just brings you to a
dead stop.

Thanks for the suggestion - I'll return to it later and see if it's been
fixed.

~~~
wikwocket
Here are my notes/bookmarks, as promised:

    
    
      http://developer.here.com/
      http://developer.here.com/javascript_api
      Docs/examples: http://developer.here.com/javascript_api_explorer
      API: http://developer.here.com/maps_js
      Daily limits: http://developer.here.com/faqs#l&t

