Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello,
i am new to writing a code in VS 2010. I have to create a windows form application in which I need to retrieve coordinates from an ms-access file and plot all the retrieved points on google map.
please tell How should i do this?
Thanks in advance :)
Posted

1 solution

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:

JavaScript
function getBuildingsCoordinates(buildingAddressAll)
{ 
    var j=0;//Counter for call back.
    var geocoder=new google.maps.Geocoder();//Creating Object.
    var tempArray = new Array();//Array holds the all building details with special characters temporary. 
    //This block is for multiple building
    if(buildingAddressAll!=null)
        { 
            tempArray = buildingAddressAll.split('~');//Getting all building details in array.
            for (var i = 0; i < tempArray.length; i++)//Loop for getting coordinates one by one of every building.
            {
                    var ArrAddress=new Array();//Holds all building addresses.
                    var tempVar=tempArray[i];   
                    buildingInfo=tempVar.split('###');//Object that holds the info of single building.
                    buildingInfoAll[i]=buildingInfo;/*Created a nested array.Each nested array contains information[kioskID,buildingID,
                                                      buildingType,buildingAddress,buildingName,buildingLatLng]of individual building.*/
                    ArrAddress[i] = buildingInfo[3];
                    var myaddress=ArrAddress[i];//This attribute hold the address of building from array of multiple building address. 
                    posn = myaddress.indexOf("%20");//Removing space from address 
                    while (posn > -1)//while there is a %20 
                    { 
                        myaddress = myaddress.substring(0,posn) + " " + myaddress.substring(posn+3); 
                        posn = myaddress.indexOf("%20");//find next %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);//Collecting address co-ordinates.
                                j++;
                                if(ArrAddress.length == j)
                                {
                                    initialize(buildingInfoAll);//Initializing map when all co-ordinates for buildings are collected. 
                                }
                            } 
                            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.

JavaScript
function initialize(buildingInfoAll) {

// Now extract the co-ordinates from the buildingInfoAll array and pass it to myLatLng. Below its given hard coded.

  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);
 
Share this answer
 
v3
Comments
Member 11774232 2-Jul-15 4:28am    
i have the multiple latitude and longitude points with me...i need to plot all of them together on gmap...
Ravi Prakash the Code-Player 2-Jul-15 4:40am    
Please refer from below code:

function getBuildingsCoordinates(buildingAddressAll)
{
var j=0;//Counter for call back.
var geocoder=new google.maps.Geocoder();//Creating Object.
var tempArray = new Array();//Array holds the all building details with special characters temporary.
//This block is for multiple building
if(buildingAddressAll!=null)
{
tempArray = buildingAddressAll.split('~');//Getting all building details in array.
for (var i = 0; i < tempArray.length; i++)//Loop for getting coordinates one by one of every building.
{
var ArrAddress=new Array();//Holds all building addresses.
var tempVar=tempArray[i];
buildingInfo=tempVar.split('###');//Object that holds the info of single building.
buildingInfoAll[i]=buildingInfo;/*Created a nested array.Each nested array contains information[kioskID,buildingID,
buildingType,buildingAddress,buildingName,buildingLatLng]of individual building.*/
ArrAddress[i] = buildingInfo[3];
var myaddress=ArrAddress[i];//This attribute hold the address of building from array of multiple building address.
posn = myaddress.indexOf("%20");//Removing space from address
while (posn > -1)//while there is a %20
{
myaddress = myaddress.substring(0,posn) + " " + myaddress.substring(posn+3);
posn = myaddress.indexOf("%20");//find next %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);//Collecting address co-ordinates.
j++;
if(ArrAddress.length == j)
{
initialize(buildingInfoAll);//Initializing map when all co-ordinates for buildings are collected.
}
}
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) {

// Now extract the co-ordinates from the buildingInfoAll array and pass it to myLatLng. Below its given hard coded.

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);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900