Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using OpenStreeMap with Google as layer, and for geocoding , nominatim service. Below, is my code.

url: "" + address + &format=json&polygon=0&addressdetails=1",
type: 'POST',
//data: { 'htmlViewType': htmlViewType },
complete: function () { },
success: function (result) {
    var obj = JSON.parse(result);
    if (obj.length > 0) {
        document.getElementById('LblError').innerHTML = obj[0].display_name;
        var markerslonLat = new OpenLayers.LonLat(obj[0].lon, obj[0].lat).transform(WGS84, map.getProjectionObject(), 0);
        map.setCenter(markerslonLat, 10);
        //var icon = new OpenLayers.Icon('', size, offset);
        var icon = new OpenLayers.Icon('', size, offset);
        markers.addMarker(new OpenLayers.Marker(markerslonLat, icon));
    else {
        document.getElementById('LblError').innerHTML = 'no such address.';
error: function (error) {
    document.getElementById('LblError').innerHTML = error;

Now, when i pass address = "Bharuch" in above URL , it returns 2 result in array, and when address = "Surat", it returns 5.

so, my question is : which result value should i take from that array result as original Result ?

Right , now i am taking result from 0 index, but in few case it don't show my actual address. Thanks.

share|improve this question
up vote 1 down vote accepted

You get multiple results because nominatim matches multiple results for your query. You can filter from the results based on the data fields that are returned in the JSON data set.

E.g. for your "Bharuch" address query you get 3 results - a county, a city and a town (the code is in python but the concept remains the same in javascript) :

import json
t=json.loads('[{"place_id":"1486447","licence":"Data \u00a9 OpenStreetMap contributors, .... 
for el in t:
...     print 'Type:' + el['type'] + ' display_name ' + el['display_name']
Type:county display_name Bharūch, Surat, India
Type:city display_name Bharuch, Bharūch, Surat, India
Type:town display_name Bharuch, Bharūch, Surat, 392001, India

For the query above, if you're looking for the city, you need to pick the entry that has 'type'='city'. Or, as an alternative, you change your search query to "Bharuch city" and you will only get 1 result from nominatim:

import urllib
import json
params = urllib.urlencode({'q':'Bharuch city', 'format':'json','polygon':0,'addressdetails':1})
f = urllib.urlopen("" % params )
t = json.loads(
for el in t:
...    print 'Type:' + el['type'] + ' display_name ' + el['display_name']
Type:city display_name Bharuch, Bharūch, Surat, India
share|improve this answer
Hi diciu, Thanks for a quick reply. I will check as per your code. Thanks a lot. – Naresh Mar 11 '13 at 7:22
Hi diciu, Thanks a lot. It working perfect. :) – Naresh Mar 11 '13 at 7:29

Your Answer


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.