Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //replacing this:
- //var geoCodeURL = "http://nominatim.openstreetmap.org/search?format=json&q=";
- //with this:
- var geoCodeURL = "http://maps.googleapis.com/maps/api/geocode/json?address=";
- var zoomToPlace = function() {
- var address = document.getElementsByName("geocoder")[0].value;
- if (!address)
- alert("Please type an address or location!");
- else {
- $.ajax({
- type: "GET",
- dataType: 'json',
- url: geoCodeURL + encodeURI(address),
- error: function(jqXHR, textStatus, errorThrown){
- alert('error: ' + textStatus + ' ' + errorThrown);
- },
- success: function (response, textStatus, XMLHttpRequest) {
- //console.log(response);
- if (!response.length) {
- alert('geocoder did not return any records');
- } else {
- // zoom to first returned
- var lng = response[0].lng;
- var lat = response[0].lat;
- {{ module }}.map.setCenter(
- new OpenLayers.LonLat( lng, lat).transform(
- new OpenLayers.Projection("EPSG:4326"),
- {{ module }}.map.getProjectionObject()
- ), 13);
- }
- }
- });
- };
- }
- // Then down in the HTML . . .
- <p>Zoom to Address:
- <input id="{{ id }}_geocoder" name="geocoder" value="">
- <button type="button" onclick="zoomToPlace()" >Go!</button>
- </p>
Advertisement
Add Comment
Please, Sign In to add comment