- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我试图通过点击平移 map 上的某个区域。该脚本不工作和页面重新加载。也许有人能看出问题所在。
我的函数
function clickroute(lati,long) {
map = google.maps.Map(document.getElementById("map_canvas"));
map.panTo(lati,long)
}
其他的
var directionDisplay;
var directionsService = new google.maps.DirectionsService();
var map;
function initialize() {
geocoder = new google.maps.Geocoder();
directionsDisplay = new google.maps.DirectionsRenderer();
var chicago = new google.maps.LatLng(41.850033, -87.6500523);
var myOptions = {
zoom:10,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: chicago
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var address = 'virginia water';
geocoder.geocode( { 'address': address}, 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
});
}
});
directionsDisplay.setMap(map);
}
function calcRoute() {
var start = document.getElementById("start").value;
var end = document.getElementById("end").value;
var request = {
origin:start,
destination:end,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}
还有我的事件
<a href="" onclick="clickroute(51.433373, -0.712251)">test</a>
最佳答案
问题是您使用的是 map.panTo(latitude,longitude)
但 google maps API 使用的是:panTo(latLng myLatLng)
其中 latLng
是一个谷歌地图类。
尝试这样的事情(未经测试)
function clickroute(lati,long) {
var latLng = new google.maps.LatLng(lati, long); //Makes a latlng
map.panTo(latLng); //Make map global
}
看here了解更多信息。
编辑正如其他人所说,您不想重新制作新 map 。也许让它全局化更容易?
关于javascript - 谷歌地图 PanTo OnClick,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6191714/
我在谷歌地图上有两个点,我想使用流畅的动画在它们之间进行转换。使用 map.panTo() 方法我可以平移它们,但动画仅在第二个点小于 map 的宽度/高度时才有效。 所以我想出的想法是将过渡分解为:
如何偏移 panTo 函数?当单击标记时我会喜欢平移到它,但不要将标记放在图像的中心屏幕。 我想将其(x 和 y)偏移屏幕宽度和高度的所需百分比。 google.maps.event.addListe
我试图通过点击平移 map 上的某个区域。该脚本不工作和页面重新加载。也许有人能看出问题所在。 我的函数 function clickroute(lati,long) { map = g
我有一张 map ,当标记被放置在 map 上时,它会围绕 map 从一点到另一点平移。我遇到的问题是平移太快了。有没有办法减慢 panTo 功能? 谢谢, 克里斯 最佳答案 遗憾的是,不,您无法更改
我试图允许用户设置他们的位置,然后让 Google map 平移到该位置。 我似乎无法让 panTo 工作,它只是重新加载页面,而不是更新我的 map 。 这里的页面: http://dub[remo
我有以下 Google map v3 JS 代码来更改当前 map 中心位置: //current map center:40.714409999999994,-74.00598000000004 (
我想创建一个 panTo 函数。当我单击链接时, map 会平移到坐标。但我不确定如何将值传递给函数。我开始为链接提供 Pointfield (pt) 值,如下所示: Link 然后我一直在尝试这个:
我想创建一张带有一些图钉的 map (使用传单)。当用户点击其中之一时, map 应该移动,直到图钉位于 map 底部的水平中心。 我的 map 是 400 像素高,所以我使用以下代码: map.pa
如何在单个指定的 panTo 调用上设置回调函数?这是我的代码。 var loc = data.split(','); map.panTo(new google.maps.LatLng(loc[0],
默认 panTo 仅平移到屏幕边缘。 我喜欢 setCenter 但想平移到这一点。欢迎任何想法 map.setCenter(mymarker.getPoint()); GEvent.tr
我正在平移到附近的位置,但 panTo 函数经常跳转到那里,因为它不在当前范围内。有时,当我这样做时, map 必须加载图像,因为我还没有去过那里,但有时它会立即从缓存加载,因为我已经去过那里。 我想
我只想移动 map 上的标记,并将变量 map、marker 声明为全局变量,但我无法在函数moveMarker()。我是 JavaScript 新手,所以这个问题可能很简单,但我仍然无法解决它 -
下面的指令不会像我预期的那样工作: map.panTo(e.latlng, {animate: true, duration: 1.0}); 我尝试过不同的值:0.5、1.0、10.0、1000.0、
我有一个 zoomend 函数,在它里面,是一个 if else 缩放值,我使用 panTo 或 setView 来缩放 latlng。但我不想在缩小时将其居中? findMapNo(no).map.
我有一张显示图 block 层的标准传单 map 。现在传单只允许您使用 panTo 方法,例如使用 LatLng, map.panTo(new L.LatLng(40.17, -98.12)); 如
我有这两行 map.panTo(respectiveMarker.getPosition());//Center in map the respective marker infoWindow.ope
我在使用加载 Google map 并不断从一个点平移到另一个点的 Web 应用程序时遇到了 Javascript 内存不足错误。大约需要半天时间才会耗尽内存,但我真的希望它能持续更长时间。我已经确定
我注意到,如果用户在 panTo 函数完成之前拖动 map , map 将继续沿之前的平移方向平移。 这是一个具有较长平移持续时间的快速 jsfiddle,可以轻松重现效果: http://jsfid
我不是开发者,卡在这个panTo()。我只想用 if-else 语句运行这个函数,而不加载新的谷歌地图,也不用 jQuery。 A
我在完成我的脚本时遇到问题,它可以使用 map.setCenter 在每个标记上重新定位,但我想平移到每个新标记。但是,当我使用 panTo 函数时,标记不会出现,尽管 map 确实显示并平移到每个新
我是一名优秀的程序员,十分优秀!