我有一张谷歌地图,半透明面板覆盖了该区域的一部分.我想调整地图的中心点,以考虑部分遮挡的地图部分.见下图.理想情况下,十字准线和引脚放置的位置将是地图的中心点.
我希望这是有道理的.
原因很简单:缩放时,需要将地图置于十字准线上而不是50%50%.此外,我将在地图上绘制标记并按顺序移动它们.当地图以它们为中心时,它们也需要处于偏移位置.
提前致谢!

我有一个使用Google Maps API显示地图的页面.当我直接加载页面时,会出现地图.但是,当我尝试使用AJAX加载页面时,我收到错误:
Uncaught ReferenceError: google is not defined
Run Code Online (Sandbox Code Playgroud)
为什么是这样?
这是带有地图的页面:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script>
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
var map;
function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer();
var chicago = new google.maps.LatLng(41.850033, -87.6500523);
var mapOptions = { zoom:7, mapTypeId: google.maps.MapTypeId.ROADMAP, center: chicago }
map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
directionsDisplay.setMap(map);
}
$(document).ready(function(e) { initialize() });
</script>
<div id="map_canvas" style="height: 354px; width:713px;"></div>
Run Code Online (Sandbox Code Playgroud)
这个带有AJAX调用的页面:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; …Run Code Online (Sandbox Code Playgroud) 在V2中有一种限制平移/拖动的方法,因此地图保持在特定范围内.怎么在V3中完成?
假设我希望用户只看欧洲.我已经限制了缩放,但是如果我允许拖动(在这种情况下我必须出于其他原因),那么用户可以超出我想要显示的区域.
请给出工作示例或代码片段 - 我不是专家编码器......
谢谢!
有没有办法可以访问Google通过网络服务提供的流量数据?
似乎有一种方法GTrafficOverlay可以将流量置于嵌入式谷歌地图上的路线之上,但是我没有直接的网络服务,例如,它可以提供源和目的地,并找到它们之间的流量?
有没有其他来源我可以从中获取这些数据?
我正在地图上绘制一系列标记(使用地图api的v3).
在v2中,我有以下代码:
bounds = new GLatLngBounds();
... loop thru and put markers on map ...
bounds.extend(point);
... end looping
map.setCenter(bounds.getCenter());
var level = map.getBoundsZoomLevel(bounds);
if ( level == 1 )
level = 5;
map.setZoom(level > 6 ? 6 : level);
Run Code Online (Sandbox Code Playgroud)
这样做可以确保地图上始终显示适当的详细程度.
我试图在v3中复制此功能,但setZoom和fitBounds似乎没有合作:
... loop thru and put markers on the map
var ll = new google.maps.LatLng(p.lat,p.lng);
bounds.extend(ll);
... end loop
var zoom = map.getZoom();
map.setZoom(zoom > 6 ? 6 : zoom);
map.fitBounds(bounds);
Run Code Online (Sandbox Code Playgroud)
我尝试过不同的排列(例如,在setZoom之前移动fitBounds)但是我对setZoom的处理似乎不会影响地图.我错过了什么吗?有没有办法做到这一点?
我正在使用fitBounds()在我的地图上设置缩放级别,也包括当前显示的所有标记.但是,当我只有一个标记可见时,缩放级别为100%(...我认为缩放级别为20 ......).但是,我不希望它被放大,因此用户可以调整标记的位置而不必缩小.
我有以下代码:
var marker = this.map.createMarker(view.latlng, this.markerNumber);
this.map.bounds.extend(view.latlng);
this.map.map.setCenter(this.map.bounds.getCenter());
this.map.map.fitBounds(this.map.bounds);
if (this.markerNumber === 1) {
this.map.map.setZoom(16);
}
this.markerNumber++;
Run Code Online (Sandbox Code Playgroud)
其中this.map.bounds先前定义为:
this.map.bounds = new google.maps.LatLngBounds();
Run Code Online (Sandbox Code Playgroud)
但是,我遇到的问题是this.map.map.setZoom(16);如果我使用该行不起作用this.map.map.fitBounds(this.map.bounds);,但是,我知道这行代码是正确的,因为当我注释掉fitBound()行时,setZoom()神奇地开始运行.
我有什么想法解决这个问题?我正在考虑设置一个maxZoom级别作为替代,如果我不能让它工作.
javascript google-maps google-maps-api-3 google-maps-markers
我喜欢跟踪我的谷歌地图界面上打开的任何和所有信息窗口(我将他们的名字存储在一个数组中),但我无法弄清楚如何通过"x"关闭它们从阵列中删除它们"在每个人的右上角.
我可以听一些回调吗?或者也许我可以做点什么
addListener("close", infowindow1, etc?
当使用Google Maps API在jQuery UI选项卡中呈现地图时,有许多问题似乎都是众所周知的.我已经看到关于类似问题发布的SO问题(例如这里和这里),但那里的解决方案似乎只适用于Maps API的v2.我检查过的其他参考文献在这里和这里,以及我可以通过谷歌搜索挖掘的几乎所有内容.
我一直在尝试将地图(使用API的v3)填充到具有混合结果的jQuery选项卡中.我正在使用最新版本的一切(目前jQuery 1.3.2,jQuery UI 1.7.2,不了解Maps).
这是标记和javascript:
<body>
<div id="dashtabs">
<span class="logout">
<a href="go away">Log out</a>
</span>
<!-- tabs -->
<ul class="dashtabNavigation">
<li><a href="#first_tab" >First</a></li>
<li><a href="#second_tab" >Second</a></li>
<li><a href="#map_tab" >Map</a></li>
</ul>
<!-- tab containers -->
<div id="first_tab">This is my first tab</div>
<div id="second_tab">This is my second tab</div>
<div id="map_tab">
<div id="map_canvas"></div>
</div>
</div>
</body>
Run Code Online (Sandbox Code Playgroud)
和
$(document).ready(function() {
var map = null;
$('#dashtabs').tabs();
$('#dashtabs').bind('tabsshow', function(event, ui) { …Run Code Online (Sandbox Code Playgroud)