GeoNames Home | Postal Codes | Download / Webservice | About 

GeoNames Forum
  [Search] Search   [Recent Topics] Recent Topics   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
Problem with service findNearbyJSON  XML
Forum Index -> General
Author Message
street_traveler



Joined: 08/03/2011 22:33:13
Messages: 2
Offline

Hi everybody

I have problem with findNearbyJSON web-service
I'm requesting it with such parameters in jQuery

Code:
 $.ajax({
         url: "http://api.geonames.org/findNearbyJSON",
         dataType: 'json',
         data: {
           lat: pos.lat(),
           lng: pos.lng(),
           featureClass: 'P',
           featureCode: ['PPLA','PPLA2', 'PPLA3', 'PPLA4'],
           username: 'user_name',
           style: 'MEDIUM',
           lang: 'local',
           radius: 20,
           maxRows: 40
         },
         jsonp: false,
         jsonpCallback: "callbackName",
         success: on_city_found_callback
       });
 


Now I wonder why in response I get places with FeatureCode PPL and other. I want only those featureCodes that I provide in array when requesting service? Can somebody help me with that?
marc



Joined: 08/12/2005 07:39:47
Messages: 4501
Offline

Are you sure you tried this code?

In the logfiles I see a couple of requests like this:
featureClass=P&featureCode=PPLC&featureCode=PPLA&featureCode=PPLA2&featureCode=PPLA3&featureCode=PPLA4&featureCode=PPL&

It is explicitly asking for PPL

Best

Marc

[WWW]
street_traveler



Joined: 08/03/2011 22:33:13
Messages: 2
Offline

Hi. I solve this couple days ago so I post a solution to all who use jQuery with geonames.

In general jQuery by default when serializing parameters use for arrays notation with braces[]. This is in general ok for php server side engine. But Java, jsp, servlet containers didn't understand such notatnion with braces so the solution is to add one parameter in ajax method:
Code:
 traditional:true
 

I think that on geonames they are using some Java technology so this is the solution for jQuery.
Code:
 $.ajax({
          url: "http://api.geonames.org/findNearbyJSON",
          dataType: 'json',
          traditional: true,
          data: {
            lat: pos.lat(),
            lng: pos.lng(),
            featureClass: 'P',
            featureCode: ['PPLA','PPLA2', 'PPLA3', 'PPLA4'],
            username: 'user_name',
            style: 'MEDIUM',
            lang: 'local',
            radius: 20,
            maxRows: 40
          },
          success: on_city_found_callback
        });
 
 
Forum Index -> General
Go to:   
Powered by JForum 2.1.5 © JForum Team