Changeset 373


Ignore:
Timestamp:
Nov 19, 2006, 11:48:10 AM (13 years ago)
Author:
David Sheldon
Message:

If the location looks like a postcode, use our geocoder.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/npemap.org.uk/static/tiles/mapTiles.js

    r361 r373  
    509509}
    510510
     511function postcodeLoc(jData) {
     512  if (jData == null) {
     513    // There was a problem parsing search results
     514    return;
     515  }
     516  gotoLocation(Math.round(jData.e/1000), Math.round(jData.n/1000), 1);
     517
     518}
    511519
    512520function find() {
    513521  var where = $('where').value;
    514522  if (where.length > 0) {
    515      request = 'http://ws.geonames.org/searchJSON?name=' +  encodeURIComponent(where)  + '&callback=getLocation&country=GB&fclass=P&fclass=T&style=SHORT';
     523    if (where.toUpperCase().match(/^([A-Z]+\d+[A-Z]?)\s*(\d[A-Z][A-Z])?$/)) {
     524      request = "/cgi/geocoder.fcgi?postcode=" + encodeURIComponent(where) + "&callback=postcodeLoc&format=js";
     525     
     526    } else {
     527      request = 'http://ws.geonames.org/searchJSON?name=' +  encodeURIComponent(where)  + '&callback=getLocation&country=GB&fclass=P&fclass=T&style=SHORT';
     528    }
    516529    aObj = new JSONscriptRequest(request);
    517530    // Build the script tag
Note: See TracChangeset for help on using the changeset viewer.