wboykinm

geocoder- nominatim to google

Jul 28th, 2011
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //var geoCodeURL = "http://nominatim.openstreetmap.org/search?format=json&q=";
  2. var geoCodeURL = "http://maps.googleapis.com/maps/api/geocode/json?";
  3. var zoomToPlace = function() {
  4.    var address = document.getElementsByName("geocoder")[0].value;
  5.    if (!address)
  6.       alert("Please type an address or location!");
  7.    else {
  8.        $.ajax({
  9.               type: "POST",
  10.               dataType: 'json',
  11.               url: geoCodeURL + encodeURI(address),
  12.               error: function(jqXHR, textStatus, errorThrown){
  13.                 alert('error: ' + textStatus + ' ' + errorThrown);
  14.               },
  15.               success: function (response, textStatus, XMLHttpRequest) {
  16.                   //console.log(response);
  17.                   if (!response.length) {
  18.                      alert('geocoder did not return any records');
  19.                   } else {
  20.                       // zoom to first returned
  21.                       var lng = response[0].lng;
  22.                       var lat = response[0].lat;
  23.                       {{ module }}.map.setCenter(
  24.                          new OpenLayers.LonLat( lng, lat).transform(
  25.                             new OpenLayers.Projection("EPSG:4326"),
  26.                             {{ module }}.map.getProjectionObject()
  27.                          ), 13);
  28.                   }
  29.               }
  30.         });
  31.   };
  32. }
Add Comment
Please, Sign In to add comment