谷歌地图显示问题 [英] Google Map display problem

查看:77
本文介绍了谷歌地图显示问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

0下来投票最爱





i我试图在联系我们页面显示谷歌地图,不知道实际问题是什么它没有显示,下面是我的代码

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

<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

推荐答案

这应该可以帮到你沿:

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>


这篇关于谷歌地图显示问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆