如何在jquerymobile中同时放置两个定位的经纬度位置
how to place two located latitude and longitude place same time in jquery mobile
我们需要一次显示两个位置的纬度和经度。我们有两套像这样的经纬度
[{"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个位置任何人都告诉我我的代码出了什么问题。请指导我。
假设您有这个数组
var markersArray = [{"Longitude":"17.4954","Lattitude":"78.2960","UserID":3},{"Longitude":"17.3616","Lattitude":"78.4747","UserID":3}]
所以如果你运行console.log(markersArray.length)
,你会得到这个输出
2
现在我们还好吗?
现在我们需要一个带有for循环的函数来创建基于markersArray
的标记
像这样的函数。
function createMarkers(){
for(var i = 0 ; i <markersArray.length ; i++) {
lat = markersArray[i].Lattitude;
long = markersArray[i].longitude;
var marker = new google.maps.Marker({
position: new google.maps.LatLng(lat, long),
map: map,
icon: 'http://maps.google.com/mapfiles/ms/icons/blue-dot.png'
});
}
}
解释我需要将您的代码放在我的代码中的何处
您需要将此代码放置在initializeMap()
函数(或用于初始化映射的任何函数名)中。
createMarkers()
<--像这个
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));
});
相关文章:
- JQuery合并了keyup和focusout两个函数
- 如何使用 node.js 比较两个 json 数组
- 为复选框javascript指定两个值
- 用每小时的差值填充数组/列表-从下拉列表中给定两个时间值
- 单击时切换两个图像
- 我可以'我似乎不知道如何修复javascript中的两个lint.有人能帮我理解吗
- 基于两个条件退出While循环
- 如何在这里将两个值最低的数字相加
- 组合两个javascript函数
- 如何使用offer/answer交换来自两个对等连接的流
- jsf中两个字符串的颜色代码差异
- 如何在jquerymobile中同时放置两个定位的经纬度位置
- JavaScript - 定位两个元素之间的字符串
- 两个网络组件之间的绑定:谷歌地图+地理定位
- 如何定位两个元素之间的文本
- 单击过滤器定位两个元素
- 我告诉我的计算机允许对localhost进行地理定位,但我仍然得到两个坐标的空值.我该如何解决这个问题呢?
- 旋转图像到两个值之间的角度,并重新定位图像中心
- 当两个元素具有相同属性时,在Protractor中定位元素
- 在 JavaScript 中计算两个地理定位之间的距离