gpt4 book ai didi

javascript - 从纬度和经度生成谷歌地图

转载 作者:行者123 更新时间:2023-12-03 08:25:06 26 4
gpt4 key购买 nike

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

<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>

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

最佳答案

您多次添加代码

这有效:

<!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>

fiddle 示例:https://jsfiddle.net/eugensunic/wexd3spp/1/

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

关于javascript - 从纬度和经度生成谷歌地图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33587728/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com