Hi,
You can use gmap v3 version. Just take the address from your database use geocoder of gmap and pass that address to it. This will give you the co-ordinates i.e. latitude and longitude now plot it on the map.
Please refer from below code:
function getBuildingsCoordinates(buildingAddressAll)
{
var j=0;
var geocoder=new google.maps.Geocoder();
var tempArray = new Array();
if(buildingAddressAll!=null)
{
tempArray = buildingAddressAll.split('~');
for (var i = 0; i < tempArray.length; i++)
{
var ArrAddress=new Array();
var tempVar=tempArray[i];
buildingInfo=tempVar.split('###');
buildingInfoAll[i]=buildingInfo;
ArrAddress[i] = buildingInfo[3];
var myaddress=ArrAddress[i];
posn = myaddress.indexOf("%20");
while (posn > -1)
{
myaddress = myaddress.substring(0,posn) + " " + myaddress.substring(posn+3);
posn = myaddress.indexOf("%20");
};
if(!myaddress)
{
alert('Address not found for building: '+buildingInfoAll[i][4]);
}
else
{
geocoder.geocode( { 'address': myaddress}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK)
{
buildingInfoAll[j].push(results[0].geometry.location);
j++;
if(ArrAddress.length == j)
{
initialize(buildingInfoAll);
}
}
else
{
alert('Geocode was not successful for Building '+buildingInfoAll[i][4]+' due to: ' + status);
}
});
}
}
}
In the above code I am finding all the latitude and longitude and holding in buildingInfoAll array once all the co-ordinates you got a call back function called which calls intialize method by passing this array i.e. buildingInfoAll.
function initialize(buildingInfoAll) {
var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
var mapOptions = {
zoom: 4,
center: myLatlng
}
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'Hello World!'
});
}
google.maps.event.addDomListener(window, 'load', initialize);