当鼠标光标纬度等于标记纬度时,发出警报(Google Maps API v3)
Alert a message when mouse cursor latitude is equal to markers latitude (Google Maps API v3)
我最近开始研究谷歌地图API V3,现在我陷入了一个问题。
我在地图上画了两个记号。我想要的是,在地图上移动鼠标光标时,它会不断检查纬度,当纬度等于地图上标记的纬度时,它应该显示一条警告消息。
我面临的问题是,它只适用于一个标记,而不适用于地图上的所有标记
这是我的代码:
$.ajax({
type: "GET",
url: $('meta[name="_home_url"]').attr('content') + '/walkalong/' + position.coords.latitude + "/" + position.coords.longitude,
success: function (response) {
// Looping through all the entries from the JSON data
for (var i = 0; i < response.data.shops.length; i++) {
// Current object
var obj = response.data.shops[i];
// Sets the map marker
var marker = new google.maps.Marker({
position: new google.maps.LatLng(obj.latitude, obj.longitude),
map: map,
info: contentString,
optimized: false,
icon: pinIcon,
id: obj.shop_id,
animation: google.maps.Animation.DROP,
title: obj.title // this works, giving the marker a title with the correct title
});
google.maps.event.addListener(map, 'mousemove', function (event) {
Latfetch = event.latLng.lat().toFixed(4);
Longfetch = event.latLng.lng().toFixed(4);
if (Latfetch === obj.latitude) {
alert(obj.latitude);
}
});
JSON响应为:
{"status":200,"data":{"shops":[{"shop_id":7,"name":"reebok","logo":"543813f8-cc75-4217-a3d4-bb08992f66af.png","latitude":"17.4539","longitude":"78.3902","shop_description":"","opening_time":"09:00:00","closing_time":"18:00:00","mobile":"4567896545","address_line1":"ameerpet","city":"Dispur","state":"Arunachal Pradesh","country":"India","pincode":"435645","baazar_area":"","front_image":"6c08a359-fb7f-4e09-af25-3c2d43a32327.jpg","distance":0.703},{"shop_id":9,"name":"ahex","logo":"86c6f7f8-625c-4a7a-aee4-10f7d16f1f12.jpg","latitude":"17.4519","longitude":"78.3879","shop_description":"","opening_time":"09:00:00","closing_time":"18:00:00","mobile":"4233488384","address_line1":"madhapur","city":"Panaji","state":"Goa","country":"India","pincode":"345678","baazar_area":"","front_image":"31e96273-c360-4b49-87d1-418bdac26dc3.jpg","distance":0.711}],"shopImages":[{"logo":"543813f8-cc75-4217-a3d4-bb08992f66af.png","front_image":"6c08a359-fb7f-4e09-af25-3c2d43a32327.jpg","internal_image":"e988011f-f2c1-4b08-8582-0f36e85dc4f9.jpg","rack_image":"rack.jpeg","product_image":"item.jpeg"}]}}
有谁能帮忙吗?
我只能猜测它只适用于一个,因为您只能为mousemove
添加一个侦听器。您可以在标记上添加事件:
for (var i = 0; i < response.data.shops.length; i++) {
...
var marker = new google.maps.Marker({
...
});
marker.addListener('mousemove', function(event) {
var latfetch = event.latLng.lat().toFixed(4);
var longfetch = event.latLng.lng().toFixed(4);
var lat = this.position.lat();
if(latfetch === lat){
alert(lat);
}
});
}
相关文章:
- 使用API在我的网站Google-Map上显示搜索地址的纬度和经度
- 当鼠标光标纬度等于标记纬度时,发出警报(Google Maps API v3)
- 将诸如“;纽约水牛城”;使用Google Maps API将地图转换为纬度和经度
- 当现有 Google 标记移动到另一个位置时,如何更新新的纬度和经度
- 使用Google API获取位置的纬度和经度,并传递变量
- 使用Google Api设置纬度和经度参数
- 使用google.maps.geocoder检索位置的纬度/经度
- 如何在Google地图API v3 javascript中获得地图的纬度,经度
- 如何在特定纬度和经度的v3 Google Map上绘制HTML元素
- Laravel和google地图:为每个纬度/经度显示标记或地图
- Google地图每隔x秒设置标记纬度和经度
- Google Maps JS API -查找给定位置(纬度/经度)的地名
- Google地图API -在文本框中显示多个形状的经度和纬度
- 从google map v3方向api的结果中获取纬度和经度
- 从JSON格式的servlet请求中获取纬度和经度,并在google地图对象中打印出来
- 将多个纬度和经度从servlet传递到jsp到Google地图
- 基于解析的XML纬度和经度值对Google地图居中
- 限制Google API地图中经度和纬度返回的小数点数
- 使用Javascript从Google融合表中的kml字段中提取纬度和经度
- 如何使用Google Javascript v3 Geocoder返回纬度和经度数组