Javascript 谷歌地图API设置地图的具体位置和搜索

Javascript 谷歌地图API设置地图的具体位置和搜索,javascript,google-maps,google-maps-api-3,Javascript,Google Maps,Google Maps Api 3,是否可以在我的网页上找到所有地图?我希望它只显示特定的位置,例如城市 如何搜索特定位置,而不是整个地图 //这是我们允许的最小缩放级别 var minZoomLevel=5; var map=new google.maps.map(document.getElementById('map'){ zoom:minZoomLevel, 中心:新google.maps.LatLng(38.50,-90.50), mapTypeId:google.maps.mapTypeId.ROADMAP });

是否可以在我的网页上找到所有地图?我希望它只显示特定的位置,例如城市

如何搜索特定位置,而不是整个地图


//这是我们允许的最小缩放级别
var minZoomLevel=5;
var map=new google.maps.map(document.getElementById('map'){
zoom:minZoomLevel,
中心:新google.maps.LatLng(38.50,-90.50),
mapTypeId:google.maps.mapTypeId.ROADMAP
});
//前往北美的边界
var strictBounds=new google.maps.LatLngBounds(
新google.maps.LatLng(28.70,-127.50),
新google.maps.LatLng(48.85,-55.90));
//收听dragend事件
google.maps.event.addListener(映射'dragend',函数(){
if(strictBounds.contains(map.getCenter())返回;
//我们超出边界-将地图移回边界内
var c=map.getCenter(),
x=c.lng(),
y=c.lat(),
maxX=strictBounds.getNorthEast().lng(),
maxY=strictBounds.getNorthEast().lat(),
minX=strictBounds.getSouthWest().lng(),
minY=strictBounds.getsoutwest().lat();
如果(xmaxX)x=maxX;
如果(ymaxY)y=maxY;
map.setCenter(新的google.maps.LatLng(y,x));
});
//限制缩放级别
google.maps.event.addListener(映射'zoom_changed',函数(){
if(map.getZoom()
我们是来教育的。请解释为什么你的答案有助于解决老年退休金计划的问题,以便他们可以学习以供将来参考。
  <div id="map" style="width: 400px; height: 300px;"></div>    

 // This is the minimum zoom level that we'll allow
     var minZoomLevel = 5;

     var map = new google.maps.Map(document.getElementById('map'), {
         zoom: minZoomLevel,
         center: new google.maps.LatLng(38.50, -90.50),
         mapTypeId: google.maps.MapTypeId.ROADMAP
     });

     // Bounds for North America
     var strictBounds = new google.maps.LatLngBounds(
     new google.maps.LatLng(28.70, -127.50),
     new google.maps.LatLng(48.85, -55.90));

     // Listen for the dragend event
     google.maps.event.addListener(map, 'dragend', function () {
         if (strictBounds.contains(map.getCenter())) return;

         // We're out of bounds - Move the map back within the bounds

         var c = map.getCenter(),
             x = c.lng(),
             y = c.lat(),
             maxX = strictBounds.getNorthEast().lng(),
             maxY = strictBounds.getNorthEast().lat(),
             minX = strictBounds.getSouthWest().lng(),
             minY = strictBounds.getSouthWest().lat();

         if (x < minX) x = minX;
         if (x > maxX) x = maxX;
         if (y < minY) y = minY;
         if (y > maxY) y = maxY;

         map.setCenter(new google.maps.LatLng(y, x));
     });

     // Limit the zoom level
     google.maps.event.addListener(map, 'zoom_changed', function () {
         if (map.getZoom() < minZoomLevel) map.setZoom(minZoomLevel);
     });