Got it working!
For those interested; the following code passes lat/lng and zoom level
into three form input elements (one for lat, one for lng and one for
zoom level):
The script:
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<script type="text/javascript">
var map = null;
var geocoder = null;
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(37.4419, -122.1419), 1);
map.setUIToDefault();
// Update map's center lat/lng coordinates and zoom level
whenever
map is dragged or zoom level changed
GEvent.addListener(map, 'move', function() {
document.getElementById("lat").value=map.getCenter().lat();
document.getElementById("lng").value=map.getCenter().lng();
document.getElementById("zoom").value=map.getZoom();
});
geocoder = new GClientGeocoder();
}
}
function showAddress(address) {
if (geocoder) {
geocoder.getLatLng(
address,
function(point) {
if (!point) {
alert(address + " Not found.");
} else {
map.setCenter(point, 12);
}
}
);
}
}
</script>
The map (with geocoding):
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<div id="map_canvas" style="position:absolute; left:6px; top:300px;
width:528px; height:350px; border-width:1px; border-style:solid;
border-color:#888888;"></div>
<form action="#" onsubmit="showAddress(this.address.value); return
false">
<input type="text" style="width:410px; left:6px; top:1000px;"
name="address" />
<input type="submit" style="width:100px; left:610px; top:1000px;"
value="Locate" />
</form>
The form elements:
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<input type="text" id="lat" name="lat" style="width:200px;
position:absolute; left:6px; top:100px;">
<input type="text" id="lng" name="lng" style="width:200px;
position:absolute; left:6px; top:125px;">
<input type="text" id="zoom" name="zoom" style="width:200px;
position:absolute; left:6px; top:150px;">
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Maps API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/google-maps-api?hl=en
-~----------~----~----~----~------~----~------~--~---