我使用DirectionsRenderer開發了一個包含路線的地圖......如果起點和目的地在同一地點,我需要將目的地標記反彈......但是當我檢查兩個LatLng值是否與IF相同時,程序會執行不執行IF語句...目的地標記沒有被退回..我的編碼是如何使用google map api v3中的if條件檢查兩個LatLng值?
var myOptions =
{
center: new google.maps.LatLng(default_latitude,default_longitude),
zoom: 4,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map"),myOptions);
var latlng1=new google.maps.LatLng(glat,glon);
var latlng2=new google.maps.LatLng(hlat,hlon);
var marker = new google.maps.Marker({
icon: "http://www.googlemapsmarkers.com/v1/B/67BF4B/000000/00902C/",
position: new google.maps.LatLng(glat,glon),
map: map
});
var marker1 = new google.maps.Marker({
icon: " http://www.googlemapsmarkers.com/v1/A/67BF4B/000000/00902C/",
position: new google.maps.LatLng(hlat,hlon),
map: map
});
//THIS IF STATEMENT IS NOT WORKING ... WHAT CAN I USE INSTEAD OF THIS
if(latlng1==latlng2)
marker1.setAnimation(google.maps.Animation.BOUNCE);
directionsDisplay.setMap(map);
directionsDisplay.setPanel(document.getElementById("panel"));
var request = {
origin: latlng1,
destination:latlng2,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
但是看,如果你想通過位置附近檢查您可以使用@ geocodezip的解決方案 – Kris 2013-03-13 06:36:07
雅肯定朋友...顯然是一個精心設計的解決方案...將在未來使用geocodezip的代碼非常精確地映射api ...感謝您的支持rt – Ree 2013-03-13 06:43:55