我们需要一次显示两个位置的经度和纬度。我们有两组纬度和经度,如下所示
[{"Longitude":"17.4954","Lattitude":"78.2960","UserID":3},{"Longitude":"17.3616","Lattitude":"78.4747","UserID":3}]
我的问题是仅显示最后一个经度和纬度
$(all).each(function () {
alert(this.Longitude);
alert(this.Lattitude);
debugger;
directionsDisplay = new google.maps.DirectionsRenderer();
var mapCenter = new google.maps.LatLng(this.Longitude, this.Lattitude);
debugger;
var myOptions = {
zoom:7,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: mapCenter
}
debugger;
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
directionsDisplay.setMap(map);
// directionsDisplay.setPanel(document.getElementById("directions"));
// marker will be displayed on the lat long position
var marker = new google.maps.Marker({
position:mapCenter,
map: map
});
});
所有变量都动态获取数据,这意味着一段时间后还会有10个位置。有人告诉我我的代码有什么问题。请指导我。
的HTML
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=true"></script>
<div id="map_canvas" style="width:100%;height:100%; position:absolute;"></div>
JAVASCRIPT
var all=[{"Longitude":"17.3616","Lattitude":"78.4747","UserID":3},{"Longitude":"17.4954","Lattitude":"78.2960","UserID":3}];
var map;
var infowindow = new google.maps.InfoWindow();
$(all).each(function (key, value) {
if(key == 0){
map = new google.maps.Map(document.getElementById('map_canvas'), {
zoom: 6,
center: new google.maps.LatLng(this.Lattitude, this.Longitude),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
}
var marker = new google.maps.Marker({
position: new google.maps.LatLng(this.Lattitude, this.Longitude),
map: map
});
var content = this.Lattitude+", "+this.Longitude;
google.maps.event.addListener(marker, 'click', (function(marker, key) {
return function() {
infowindow.setContent(content);
infowindow.open(map, marker);
}
})(marker, key));
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句