Search code examples
urlhttpwebrequestwikimapia

Using the Wikimapia.org Api


I am trying to use the wikimapia api for finding venues of specific cities or places given their longitude and latidute. There isn't much of some documentation, but I suppose that it would just be an http request. Now, the problem I have is about the specific ulr. I tried this one:

http://api.wikimapia.org/?function=search
&key= myKey
&q=lat= theLatidute
&lon= theLongitude
&format=json

but it doesn't seem to work. Any help will be appreciated..


Solution

  • The search API requires that you set a search location (long and lat) as well as the name of something to search for that location.

    For example, to find a train station near a particular coordinate:

    http://api.wikimapia.org/?function=search&key=[key]&q=Train+Station&lat=[latitude]&lon=[longitude]&format=json
    

    If you're just trying to find a list of objects that are close to a coordinate, without a search term, you need to use the box API with small offsets:

     http://api.wikimapia.org/?function=box&key=[key]&lon_min=[lon_min]&lat_min=[lat_min]&lon_max=[lon_max]&lat_max=[lat_max]&format=json
    

    If you only want to input one set of coordinates, you can compute lon_min, lon_max, lat_min and lat_max like this:

    // 1 degree latitude is roughly 111km, 0.001 degrees lat is about 100m
    var lat_min = latitude - 0.001;
    var lat_max = latitude + 0.001;
    
    // 1 degree longitude is not a static value
    // it varies in terms of physical distance based on the current latitude
    // to compute it in meters, we do cos(latitude) * 111000
    var meters_per_longdeg = Math.cos((3.141592 / 180) * latitude) * 111000;
    
    // then we can work out how much longitude constitutes a change of ~100m
    var range = 100 / meters_per_longdeg;
    
    var long_min = longitude - range;
    var long_max = longitude + range;