google-maps - 带有邮政编码的谷歌地图街景

标签 google-maps postal-code

我正在尝试在护目镜街道 map 中应用新加坡邮政编码。我在位置变量中传递邮政编码,但是当我更改邮政编码时, map 位置无法更改。不知道我哪里错了。请帮忙。这是新加坡的一些邮政编码:189969、189927 这是我的代码

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title></title>
<script type='text/javascript' src='mootools-core-1.3.2.js'></script>
<link rel="stylesheet" type="text/css" href="/css/normalize.css">
<style type='text/css'>
#map_canvas {
    background:#ccc;
    height:400px;
    width:100%;
}
</style>
<script type='text/javascript'>//<![CDATA[ 
window.addEvent('load', function() {
var map;
var geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(1.280095,103.850949);

var panoramaOptions = {
    position: latlng,
};
map = new google.maps.StreetViewPanorama(document.getElementById('map_canvas'),panoramaOptions);

var locations = ['189969'];
function codeAddress(locations) {
    for (i = 0; i < locations.length; i++) {
        geocoder.geocode( { 'address': locations[i]}, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                map.setCenter(results[0].geometry.location);
                var marker = new google.maps.Marker({
                    map: map, 
                    position: results[0].geometry.location
                });
            } else {
                alert("Geocode was not successful for the following reason: " + status);
            }
        });
    }

}
codeAddress(locations);
});//]]>  
</script>
</head>
<body>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<div id="map_canvas">map</div>
</body>
</html>

最佳答案

修改您的代码,使 map 成为 google.maps.Map 对象。

当您想要显示 map 的街景时(例如在 geocoder.geocode() 的回调中),您必须:

  1. 设置街景位置
  2. 设置街景的可见性

示例:

map.streetView.setPosition(results[0].geometry.location);
map.streetView.setVisible(true);

演示:http://jsfiddle.net/doktormolle/7J4G6/

还有更多选项来控制街景(例如,我建议检查给定位置是否有街景),但上面的两行是最低要求。

关于google-maps - 带有邮政编码的谷歌地图街景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14290794/

相关文章:

javascript - 为什么Google Geocoding即使在计费和通话之间存在延迟的情况下仍能提供OVER_QUERY_LIMIT?

c# - GMAP 使用谷歌卫星层

ios - 根据 swift map 的缩放级别,在 Google map 中显示某个区域中的标记数量

php - 如何从英国邮政编码获取地理位置

python - 计算邮政编码/邮政编码 python 之间的(公路旅行)距离

javascript - 为邮政编码添加正确的空格(英国)

android - 将 rxJava 与 MVP 结合使用的 GoogleMaps

php - 加拿大邮政编码半径

Python,正则表达式邮政编码搜索

javascript - PHP 查询数组到 Javascript Google map 迭代器