Click here to Skip to main content
15,888,351 members
Articles / Web Development / ASP.NET

Google Maps StreetView

Rate me:
Please Sign up or sign in to vote.
4.38/5 (5 votes)
15 Oct 2010CPOL2 min read 92.5K   3.1K   53  
A user friendly way of using the Google Maps streetview
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>Google Maps StreetView Example</title>
    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=abcdefg&sensor=true_or_false"
            type="text/javascript"></script>
    <script type="text/javascript">
	var marker = null;
	var myPano = null;

	function openWindow()
	{
		myPano = new GStreetviewPanorama(document.getElementById("stview"));
		var latlang = marker.getLatLng();
		myPano.setLocationAndPOV(latlang);

	}


    function initialize() {
      if (GBrowserIsCompatible()) {
		




	myPano = new GStreetviewPanorama(document.getElementById("stview"));
 
        map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(37.4419, -122.1419), 13);
        map.setUIToDefault();
	var streetOverlay = new GStreetviewOverlay();
			var latlang = map.getCenter(); 

	
			
		        var icon = new GIcon();
			
		
		
                var imageUrl = "http://maps.gstatic.com/mapfiles/cb/man_arrow-0.png";
                icon.image = imageUrl;
                icon.iconSize = new GSize(49,52);
                icon.iconAnchor =  new GPoint(25,36);
                icon.infoWindowAnchor = new GPoint(25,6);      
                marker = new GMarker(latlang, {"icon":icon, "draggable":true});
		GEvent.addListener(marker, "dragstart", function()
                   {     
                        map.addOverlay(streetOverlay);
                   }
                ); 
	
		GEvent.addListener(marker, "dragend", function(overlay,latlang)
                   {            
                        map.removeOverlay(streetOverlay);
						openWindow();
                   }
                );



		map.addOverlay(marker);

      }
    }

    </script>
  </head>
  <body onload="initialize()" onunload="GUnload()">
    <div id="map_canvas" style="width: 500px; height: 300px"></div>
	<div id="stview" style="width: 500px; height: 200px"></div>

  </body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Software Developer
Sri Lanka Sri Lanka
I came to the the software industry in 2006 now i am familiar with C#, ASP.NET, SQL Server, JavaScript,Google Maps and Virtual Earth API and looking forward for a long way ahead.

Comments and Discussions