JavaScript for Google Map


var map = null;
var point = null;
var mmarker = null;
var arr = new Array(“54.04″,”-1.34″,”54.04″,”-1.34″); // this can set the initial location for people, when all the app complete the data can be changed by server using the real-time location from the database.

function addIconImages(){
for(i=0;i<arr.length;i=i+2){
map.newMarker = new GMarker(new GLatLng(arr[i],arr[i+1]), {draggable: false, bouncy: true});
map.addOverlay(map.newMarker);
}
// adding the unmovable tag in the map using the data from arr.

function load(){
if (GBrowserIsCompatible()) {//checking the browser.
map = new GMap2(document.getElementById(“map”)); //create the map object.
map.addControl(new GLargeMapControl()); // make the map control to be enable
map.addControl(new GScaleControl()); // make the scale control to be enable
map.enableDragging(); // make the map can be dragged
map.enableContinuousZoom(); //make the map can use the continuous zoom.
map.enableScrollWheelZoom(); //let user can use the wheel

if(arr.length < 2){
//when there is no location stored in arr
point = new GLatLng(50.88,-1.24); //set the Southampton’s location as the initial location
map.setCenter(point,12); // set the certre point
}else if(arr.length == 2){
//when there is some location stored in arr
point = new GLatLng(arr[0],arr[1]); //set the initial location
map.setCenter(point,12); // set the center point

}else{
getCurrents(); //when there is over 1 tag in the map, calculate the center point
addIconImages(); //adding the unmovable tag
}
document.getElementById(“show_x”).innerHTML = point.x;
document.getElementById(“show_y”).innerHTML = point.y;
addDraggingListener(); //add the listener
}
}

code in the html:
body onload=”load();” onunload=”GUnload();”
div style=”width: 700px;height: 450px”

//using the Javascript

  1. No comments yet.
(will not be published)