Google Maps API使用jQuery Plugin:如何在点击时获取标记的纬度和经度? [英] Google Maps API using jQuery Plugin: How to get a marker's latitude and longitude on click?

查看:94
本文介绍了Google Maps API使用jQuery Plugin:如何在点击时获取标记的纬度和经度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google Maps API V3的插件。我用它在地图上放置一个标记,并允许用户将标记拖动到地图上的一个点上。我想要点击标记的lat,lng。


$ b

goMap插件页面
http://www.pittss.lv/jquery/gomap/index.php



此函数首先设置标记。

  $(#map ).goMap({
zoom:16,
maptype:'ROADMAP',
navigationControl:false,
mapTypeControl:false,
scrollwheel:true,
disableDoubleClickZoom:false,
标记:[{
draggable:true,
latitude:data.lat,
longitude:data.lng,
icon:'。 /images/pink.png'
}]
});

我试着在goMap()上调用本地getLat()方法,但我不认为我这样做是对的。任何帮助都非常感谢。

解决方案

经过一番探索后,它看起来像使用jQuery的数据()函数将数据绑定到地图。您可以通过 $('#map')。data()获取数据,其中包含有关标记的信息。

每个标记都有一个id,你可以通过数组 $。goMap.markers 获取标记的id。请注意, $。goMap.markers 只包含ID而不是标记本身。

您需要使用该数组来找到您想要的标识(或者您可能提前知道该标识),然后调用 $( '#map')。data()['MARKER_ID'] 来获取标记对象。标记有几个属性,包括 title visible 图标 id 位置



我们关心位置,它有两个属性, wa ya wa 似乎是纬度,而 ya 似乎是经度。例如, $('#map')。data()['MARKER_ID']。position.wa 会为您提供纬度。看起来有些标记具有纬度经度属性,不知道为什么这并不总是存在(从我简短的测试中至少),但您可以尝试 $('#map')。data()['MARKER_ID']。latitude



希望这有助于。


I am using a plugin for Google Maps API V3. I use it to put a marker on the map and allow the user to drag the marker to a spot on the map. I want to get the lat,lng of the marker on click.

goMap Plugin Page: http://www.pittss.lv/jquery/gomap/index.php

This function that sets up the marker in the first place.

$("#map").goMap({ 
   zoom: 16,
   maptype: 'ROADMAP',
   navigationControl: false, 
   mapTypeControl: false, 
   scrollwheel: true, 
   disableDoubleClickZoom: false,
   markers: [{  
       draggable:true,
       latitude: data.lat, 
       longitude: data.lng, 
       icon:'./images/pink.png'
  }] 
});           

I tried calling the native getLat() method on goMap(), but I don't think I was doing that right. Any help is much appreciated.

解决方案

After a bit of sleuthing, it looks like it uses jQuery's data() function to bind data to the map. You can get to the data through $('#map').data(), which has information on markers.

Each marker has an id, and you can get the marker's id through the array $.goMap.markers. Note that $.goMap.markers only contains strings that are IDs and not the markers themselves.

You'll need to use that array to find the id you want (or you might know it ahead of time) and then call $('#map').data()['MARKER_ID'] to get the marker object. The marker has a few properties, including title, visible, icon, id, and position.

We care about position, which has two properties, wa and ya. wa seems to be latitude, while ya seems to be longitude. So $('#map').data()['MARKER_ID'].position.wa will get you the latitude, for example. It seems some markers have a latitude and longitude property, not sure why that's not always there (from my brief testing at least), but you could try $('#map').data()['MARKER_ID'].latitude instead.

Hope this helps.

这篇关于Google Maps API使用jQuery Plugin:如何在点击时获取标记的纬度和经度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆