Once that was done I then had to create the javascript that was necessary in order to grab the coordinates and return the map to my div tag. I wanted a couple different options for users; to be able to zoom in and out of the map and to place a marker at the coordinates given to the api. I found that this was not too difficult to do.
function setupMap(lat, long) {
if (GBrowserIsCompatible()) {
var center = new GLatLng(lat, long);
map = new GMap2(document.getElementById("googlemap"));
map.addControl(new GLargeMapControl());
map.setCenter(center, 09);
var marker = new GMarker(center, {draggable: true});
GEvent.addListener(marker, "dragstart", function() {
map.closeInfoWindow();
});
GEvent.addListener(marker, "dragend", function() {
marker.openInfoWindowHtml("Just bouncing along...");
});
map.addOverlay(marker);
}
}
You'll notice that I added a couple variables to pass to the program that were filled in another function based on my user input from the web page.
function getCoord(itemName){
var lat;
var long;
if (itemName == 'snowbird')
{
lat = '40.5768173605448';
long = '-111.651607579098';
}
if (itemName == 'alta')
{
lat = '40.58889';
long = '-111.63722';
}
if (itemName == 'solitude')
{
lat = '40.621159';
long = '-111.592499';
}
if (itemName == 'vail')
{
lat = '39.3944';
long = '-106.2150';
}
if (itemName == 'taos')
{
lat = '36.39';
long = '-105.58';
}
if (itemName == 'kill')
{
lat = '43.6775';
long = '-72.7803';
}
setupMap(lat, long);
}
At the bottom of this function is where I call the setupMap() function. It then returns the following data/picture:
A Dumb Question : But how do you actually figure out the latitudes and longitudes values....for a certain place...I mean I tried to do it for my API but couldn't really understand the concept
ReplyDeleteAman I can answer that question. I found if you go to the top right of google maps and click on the green icon. Then enable LatLng Marker and it will show you the lat and long.
ReplyDeleteAdam, I am having trouble displaying the information. Do you have any suggestions for me.
I am definitely going to use this! I was looking for something that helped me change my little API link to something the user could actually read. It actually looks pretty simple, I look forward to trying it out.
ReplyDelete