简体   繁体   English

谷歌地图 - 将标记移动到基于 map div 大小的位置?

[英]Google Maps - Moving marker to location based on map div size?

Say I have a map div:假设我有一个 map div:

____________________
|                   |
|                   |
|                   |
|             m     |
|                   |
|                   |
|   x               |
|___________________|

m is where the marker is now (actually I don't really care where the marker is initially). m 是标记现在所在的位置(实际上我真的不在乎标记最初在哪里)。 I want to move the marker 5% div height, 8% div width from the bottom left corner to the x location (moving by pixels is okay too).我想将标记从左下角移动 5% div 高度,8% div 宽度到 x 位置(按像素移动也可以)。 Given that the map size can be of any size, how would I go about moving a marker from m to location x in the map.鉴于 map 大小可以是任意大小,我 go 如何将标记从 m 移动到 map 中的位置 x。

Note: Just to clarify, I don't want the location(lat, lng) of the marker to change, but rather move the map such that the marker moves in the map div to location x.注意:澄清一下,我不想更改标记的位置(纬度、经度),而是移动 map,使标记在 map div 中移动到位置 x。

OK, I put together something workable for close-up zooms (around 9 or higher).好的,我整理了一些适用于特写变焦(大约 9 或更高)的东西。 You will notice quickly at world-view zooms that it is horribly broken when the marker is near the poles or the International Date Line is visible on the map.当标记靠近两极或国际日期变更线在 map 上可见时,您会在世界观缩放时很快注意到它严重损坏。

Well, it's a starting point.嗯,这是一个起点。 http://jsfiddle.net/TQ8YY/1/ http://jsfiddle.net/TQ8YY/1/

Drag the marker to your area of interest.将标记拖到您感兴趣的区域。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM