On May 5, 6:06 am, Zeli <[email protected]> wrote:
> i am a beginner at google maps api and thought this was how to load
> the map. I am not sure as to how we can use javascript to do so.
javascript can be used to load data to the map using ajax techniques.
----------------------------------------
1. create a php page that returns JSON or XML data, for example this
"random.php"
<?PHP
header( 'Content-type: application/json');
print '{lat:63.62830,lng:-19.60535,zoom:7}';
?>
----------------------------------------
2. link the button to a javascript function:
<input type=button value="Another" onclick="randomLocation()">
----------------------------------------
3. Use GDownloadUrl to get the data from the random.php, and evaluate
into a javascript object.
Some browsers will cache the results so it's good to include a random
parameter to the script to prevent the caching of the results.
var map;
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
map.setUIToDefault();
randomLocation();
}
}
function randomLocation() {
var t = new Date().getTime();
GDownloadUrl("random.php?t=" + t, function(data, responseCode) {
var location = eval("(" + data + ")");
zoomTo(location);
});
}
function zoomTo(location) {
// setCenter of map at location and zoom
// create Marker at location
// create Click Listener on Marker
}
----------------------------------------
--
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.