繁体   English   中英

从纬度和经度生成Google地图

[英]Generating google map from Latitude and Longitude

我需要使用经度和纬度在网页中生成Google地图。 但是地图没有显示。 到目前为止,我已经尝试过如下-

<script src="plugins/jQuery/jQuery-2.1.4.min.js"></script>
<script language=javascript src='http://maps.google.com/maps/api/js?sensor=false'></script>
<div id="map"></div>
<script>
   function initialize(){
        var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
        var myOptions = {
            zoom: 4,
            center: myLatlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
            }
         map = new google.maps.Map(document.getElementById("map"), myOptions);
         var marker = new google.maps.Marker({
             position: myLatlng, 
             map: map,
         title:"Fast marker"
        });
   } 

   google.maps.event.addDomListener(window,'load', initialize); 
   $(document).ready(function (){
        var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
        var myOptions = {
            zoom: 4,
            center: myLatlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
            }
         map = new google.maps.Map($('#map'), myOptions);
         var marker = new google.maps.Marker({
             position: myLatlng, 
             map: map,
             title:"Fast marker"
        });
   }                                
</script>

如何生成地图? 在那里找不到任何错误。 请帮我。

您要多次添加代码

这有效:

<!DOCTYPE html>
<html>
<head>
<script
src="http://maps.googleapis.com/maps/api/js">
</script>

<script>
 function initialize(){
        var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
        var myOptions = {
            zoom: 4,
            center: myLatlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
            }
         map = new google.maps.Map(document.getElementById("map"), myOptions);
         var marker = new google.maps.Marker({
             position: myLatlng, 
             map: map,
         title:"Fast marker"
        });
   } 

   google.maps.event.addDomListener(window,'load', initialize); 

</script>
</head>

<body>
<div id="map" style="width:500px;height:380px;"></div>

</body>
</html>

小提琴示例: https : //jsfiddle.net/eugensunic/wexd3spp/1/

CodePen示例: http ://codepen.io/anon/pen/QjZgpw

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM