Jump to content

Google Map Api


bkkmick

Recommended Posts

Hi

Here's a little problem that's driving me nuts. I'm sure that someone will take a look and see the problem straight away.

I want to display a Google Map starting with one location and then let a user click a link to change to a different location.

The code below is based on an example I found on the web. I added the two parameters sLat and sLong.

When I click the Paris link, it briefly displays Paris CDG then reloads back to Heathrow! Grrrr...

Any ideas?

<!-- #include file="GoogleAPIKey.asp" -->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
   <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
   <title>Google Maps JavaScript API Example</title>
   <script src="http://maps.google.com/maps?file=api&v=2&key=<%=GoogleAPIKey%>" type="text/javascript"></script>
   <script type="text/javascript">
   //<![CDATA[

  function load(sLat, sLong, Locn) {
    var WINDOW_HTML = '<div style="width: 210px; 	padding-right: 10px">' + Locn + '</div>';		
    if (GBrowserIsCompatible()) 
    	{
    	sLat = parseFloat(sLat);
    	sLong = parseFloat(sLong);
      var map = new GMap2(document.getElementById("map"));
			map.addControl(new GSmallMapControl());
			map.addControl(new GMapTypeControl());
      map.setCenter(new GLatLng(sLat, sLong), 13);
			var marker = new GMarker(new GLatLng(sLat, sLong));
			map.addOverlay(marker);
			GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml(WINDOW_HTML);
	  });
			marker.openInfoWindowHtml(WINDOW_HTML);			
      }
    }
   //]]>
   </script>
 </head>
 <body onload="load('51.47063', '-0.45179', 'London Heathrow')">
   <div id="map" style="width: 600px; height: 600px"></div>
   <a href="" onClick="load('49.01425', '2.54125', 'Paris CDG');">Paris</a>
 </body>
</html>

Link to comment
Share on other sites

"return false;" after the load in the onclick should also do it.

The rest of the code looks ok and if you said you fixed it I guess it does the job.

There is however a lot more that you could take advantage of.

Custom icons, settings for scroll wheels, zoom levels for starters.

Depends what your using it for, but the maps API is very powerful.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.








×
×
  • Create New...