Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am creating a simple webmap that should be able to:

  1. Display external maptiles (any of the following: Cloudmade, Mapquest, Google).
  2. Overlay additional static layer in Geojson or KML format, that can show a popup box on a mouse-click.
  3. Use a search box for geocoding that is limited only to towns and cities. And then zoom in to the geocoded location at a specific zoom level (z8-12 in webmap speak).

I'm looking at several webmapping framework like Openlayers, Leaflet, Polymaps. So far, I was able to do 1 and 2.

I'm having difficulty integrating the third feature. There are several geocoding APIs available (OSM's Nominatim, Geonames and Google's geocoder). However, I can't find any that limits geocoding to towns/cities.

A major challenge is to do this purely on the browser/javascript, no server side processing since the webserver is only limited to static htmls.

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

You can use Google Places API to have an autocomplete for addresses. When address is selected, address_components field contains structured address data (e.g. street, city, country and lat/lng coordinates). It has both cities and addreeses in results.

Here is a short working demo:

<!DOCTYPE html>
<html>
    <head>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
    </head>
    <body>
        <input type="text" id="address" style="width: 500px;"></input>

        <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&libraries=places&language=en-AU"></script>
        <script>
            var autocomplete = new google.maps.places.Autocomplete($("#address")[0], {});

            google.maps.event.addListener(autocomplete, 'place_changed', function() {
                var place = autocomplete.getPlace();
                console.log(place.address_components);
            });
        </script>
    </body>
</html>

Another option is to use Freebase suggestion box. It can be configured to limit results by entity type (e.g. populated place). Downside is that not every freebase entity has coordinates available.

3rd option is using Dbpedia (a semantic database based on Wikipedia data). You can query it using SPARQL end limit results by article type.

share|improve this answer
    
Thanks Maksym Kozlenko, if you don't mind, I will wait for more answers before accepting your answer. –  maning Jan 3 '12 at 12:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.