Click here to Skip to main content
15,894,106 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
0 down vote favorite


i am trying to display google map in contact us page,do not know what is the actual problem it is not displaying, below is my code
JavaScript
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places">

   if (navigator.geolocation) {
       navigator.geolocation.getCurrentPosition(success);
   } else {
       alert("Geo Location is not supported on your current browser!");
   }
   function success(position) {
       var latitude = position.coords.latitude;
       var longitude = position.coords.longitude;
       var city = position.coords.locality;
       var myLatlng = new google.maps.LatLng(latitude, longitude);
       var myOptions = {
           center: myLatlng,
           zoom: 12,
           mapTypeId: google.maps.MapTypeId.SATELLITE
       };
       var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
       var marker = new google.maps.Marker({
           position: myLatlng,
           title: "lat: " + latitude + " long: " + longitude
       });

       marker.setMap(map);
       var infowindow = new google.maps.InfoWindow({ content: "User Address<br/> Latitude:" + latitude + "<br /> Longitude:" + longitude + "" });
       infowindow.open(map, marker);
   </script>


please help
Posted

1 solution

This should help you along:
<html>
  <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <style type="text/css">
      html { height: 100% }
      body { height: 100%; margin: 0; padding: 0 }
      #map_canvas { height: 100% }
    </style>
    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false">
    </script>
    <script type="text/javascript">
      function initialize() {
        var myOptions = {
          center: new google.maps.LatLng(54.270606, 22.471527),
		  //Zoom in by 8, zero would setr the earth to be fully zoomed out
          zoom: 8,
		  //Make it a road map - other options are SATELLITE, TERRAIN and HYBRID
          mapTypeId: google.maps.MapTypeId.ROADMAP,
        };
		
        var map = new google.maps.Map(document.getElementById("map_canvas"),
            myOptions);	
		// Creating a marker and positioning it on the map    
    	var marker = new google.maps.Marker({
    	position: map.getCenter(),
		icon: 'http://google-maps-icons.googlecode.com/files/factory.png',
    	map: map,
    	title: 'Click to zoom'});
		google.maps.event.addListener(map, 'center_changed', function() {
    	// 3 seconds after the center of the map has changed, pan back to the marker.
    	window.setTimeout(function() {map.panTo(marker.getPosition());}, 3000);});
		//When the marker is clicked, zoom in
  		google.maps.event.addListener(marker, 'click', function() {map.setZoom(10);
    	map.setCenter(marker.getPosition());});	
      }
    </script>
  </head>
  <body onload="initialize()">
    <div id="map_canvas" style="width:100%; height:100%"></div>
  </body>
</html>
 
Share this answer
 

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