Created
May 16, 2011 21:00
-
-
Save ryanttb/975364 to your computer and use it in GitHub Desktop.
Google geocode => OpenLayers Map.setCenter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function toWebMercator(googLatLng) { | |
// you'll have to put your conversion code here (not included in this gist) | |
return { x: googLatLng.lng(), y: googLatLng.lat() }; | |
} | |
geocoder.geocode({ address: "somewhere" }, function (result, status) { | |
if (status == google.maps.GeocoderStatus.OK && result.length > 0) { | |
var | |
first = result[0], | |
center = toWebMercator(first.geometry.location), | |
viewport = first.geometry.viewport, | |
viewportSW = viewport.getSouthWest(), | |
viewportNE = viewport.getNorthEast(), | |
min = toWebMercator(viewportSW), | |
max = toWebMercator(viewportNE), | |
zoom = mapMain.getZoomForExtent(new OpenLayers.Bounds(min.x, min.y, max.x, max.y)); | |
mapMain.setCenter(new OpenLayers.LonLat(p.x, p.y), Math.min(AppContext.addressZoom, zoom)); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment