1
最近GoogleマップAPI V3で作業を開始しましたが、今は問題に悩まされています。マウスカーソルの緯度がマーカーの緯度と等しい場合にメッセージを表示する(Google Maps API v3)
私はマップに2つのマーカーをプロットしています。私が望むのは、マウスカーソルを地図上で動かすと、緯度が連続的にチェックされ、緯度が地図上にあるマーカーの緯度と同じであれば、警告メッセージが表示されるはずです。
私が直面しています問題は、それが唯一つのマーカーのためではなく、ここでマップ
に存在するすべてのマーカーのために働いていることであることは私のコードです:
$.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"}]}}
誰でもお手伝いできますか?