gpt4 book ai didi

javascript - 从 Google map 加载 div 中的确切位置

转载 作者:行者123 更新时间:2023-11-28 13:47:03 25 4
gpt4 key购买 nike

我对在我的网站中使用 Google map 的概念相当陌生。我已经使用此脚本来加载网页中 div 中的特定位置。但是,所需的位置未加载到我的页面中。

<小时/>

假设,每当我们打开页面时,我想在 div 中加载位置 BIT Main Bldg Patna, Bihar, India 12 m E。但是,结果并不准确,我们需要再放大几层。

<小时/>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps Geocoding Demo</title>
<script src="http://maps.google.com/maps/api/js?sensor=false"
type="text/javascript"></script>
</head>
<body>
<div id="map" style="width: 400px; height: 300px;"></div>

<script type="text/javascript">

var address = 'BIT Main Bldg Patna, Bihar, India 12 m E';

var map = new google.maps.Map(document.getElementById('map'), {
mapTypeId: google.maps.MapTypeId.TERRAIN,
zoom: 8
});

var geocoder = new google.maps.Geocoder();

geocoder.geocode({
'address': address
},
function(results, status) {
if(status == google.maps.GeocoderStatus.OK) {
new google.maps.Marker({
position: results[0].geometry.location,
map: map
});
map.setCenter(results[0].geometry.location);
}
else {
// Google couldn't geocode this request. Handle appropriately.
}
});

</script>
</body>
</html>
<小时/>

您可以通过在 this 的输出文本框中输入 BIT Main Bldg Patna, Bihar, India 12 m E 来看到确切的期望结果。页。这里有什么错误?

最佳答案

要使您的页面显示与您链接到的页面上的 map 类似的 map ,您需要更改在 map 构造函数中提供的选项。将 zoom 属性更改为 15 或 16,并将 mapTypeId 更改为 google.maps.MapTypeId.ROADMAP,您的 map 将看起来更像您的 map 铭记于心。

关于javascript - 从 Google map 加载 div 中的确切位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13549881/

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