Search code examples
apiparsinggoogle-mapsstreet-address

How to detect if a query string is relevant for a Google Map Static API lookup


I am currently developing a web app that uses Google's Static Map API, in order to display maps of places upon user's request.

My problem is the following: How can I detect if a given string is relevant or not to searching Google Maps ?

Examples:

  • Searching for "North Beach San Francisco" with the following URL returns a relevant map of what is asked.
    http://maps.google.com/maps/api/staticmap?size=270x185&maptype=roadmap&sensor=false&markers=north%20beach%20san%20francisco

  • However, searching for something that is not an address like Orwell's "1984" with the following URL does also return a map but it is absolutely not relevant to the query.
    http://maps.google.com/maps/api/staticmap?size=270x185&maptype=roadmap&sensor=false&markers=1984

My point is, I don't need to parse the query since Google Maps Static API can find an address pretty easily, but I need to know if the string the user submitted should be searched in Maps or just regular search.

There is a lot of address-parsing related questions on SO, but I repeat that I don't want to have a full address parsing process, I just want to know if Google would have displayed a map link if I had searched the same thing on their website.

I do know the Google Geocoding API but it's roughly the same, as it will return coordinates even for unadapted queries like "1984". (And I'm not even talking about the limitations that make it pretty impossible to use in a large-scale web application)

Thank you for your time ! Gael


Solution

  • What I eventually did:

    Google Geocoding API has a response parameter that indicates the accuracy of the geocoding lookup. Using this parameter, I was able to determine if my query is a real address or just a standard query looking like an address.

    Keep in mind that both Geocoding Service and Javascript Geocoding API have limitations (as of now, 2,500 requests per IP per day)

    Do post a comment if you want further information about that !