从xml谷歌地图获取数据 [英] Get DATA from xml google maps
问题描述
我以XML格式从Google地图获取数据。所有功能都在工作,但我没有问题。它只显示我最后的数据。为什么是这样,我该如何解决它?
这是我的代码(
pre $函数getline(){
downloadUrl(line.php,function(doc){
var g = google.maps;
var xmlDoc = xmlParse(doc );
bounds = new google.maps.LatLngBounds();
// =========现在处理多段线====== =====
var lines = xmlDoc.documentElement.getElementsByTagName(line);
//读取每行
for(var a = 0; a< lines.length; a ++){
//获取任何线条属性
var color = lines [a] .getAttribute(color);
var width = parseFloat(lines [a]。 getAttribute(width));
var diameter = lines [a] .getAttribute(diameter);
var project = lines [a] .getAttribute(projectid);
var contract = lines [a] .getAttribute(contract);
var comp = lines [a] .getAttribute(complated);
var id = lines [a] .getAttribute(id_line);
//读取该行上的每个点
var points = lines [a] .getElementsByTagName(point);
var pts = [];
var length = 0;
var point = null;
for(var i = 0; i
parseFloat(points [i] .getAttribute(lat)));
if(i> 0){
length + = pts [i-1] .distanceFrom(pts [i]);
if(isNaN(length)){alert([+ i +] length =+ length +segment =+ pts [i-1] .distanceFrom(pts [i]))};
}
bounds.extend(pts [i]);
point = pts [parseInt(i / 2)];
var info =< b>合同:< / b> +合约+< br />< b>项目:< / b> + project +< br />< b>直径:< / b> + diameter +< br />< b> Complated:< / b> + comp +< hr>< br />< a class = \inline-link-1 \href = \#\>更改数据< / a>< a class = \inline-link-1 \href = \#\>编辑< / a>> + id +;
}
//长度* = 0.000621371192;如果(comp< 1){
colorr ='#FA0505'}
if(comp> 0&&如果(comp> 24&&comp< 50){
colorr ='#FFFD91(comp< 25){
colorr ='#FFA640'}
(comp> 49&& comp< 75){
colorr ='#E8E400'}
if(comp> 74& comp< 100){
colorr ='#BFFFAD'}
if(comp == 100){
colorr ='#0F8500'}
var polyline = new g.Polyline({
map:map,
path:pts,
strokeColor:colorr,
strokeWeight:宽度,
可点击:true
});
// createClickablePolyline(polyloine,html,label,point,length);
// map.addOverlay(polyline);
$ b google.maps.event.addListener(polyline,'mouseover',function(){
this.setOptions({strokeColor:' #690469'});
this.setOptions({strokeOpacity:1.0});
this.setOptions({strokeWeight:4});
});
google.maps.event.addListener(polyline,'mouseout',function(){
this.setOptions({strokeColor:colorr});
this.setOptions({strokeOpacity:1.0});
this.setOptions({strokeWeight:4});
});
var mpenc = new google.maps.InfoWindow();
google.maps.event.addListener(polyline,'click',function(event){
mpenc.setContent(info,this);
mpenc.setPosition(event.latLng,this) ;
mpenc.open(map);
});
}
map.fitBounds(bounds);
});
它看起来像你复制了一些代码并改变了它。为什么这个注释掉了?
// createClickablePolyline(polyline,html,label,point,length);
该函数在data,polyline和infowindow上关闭,所以它们与彼此(至少在我的代码版本中)。
I get data from Google Maps in XML format. All functions are working, but I have little problem. It only shows me the last data. Why is that, and how can I solve it?
This is my code (jsFiddle)
function getline() {
downloadUrl("line.php", function(doc) {
var g = google.maps;
var xmlDoc = xmlParse(doc);
bounds = new google.maps.LatLngBounds();
// ========= Now process the polylines ===========
var lines = xmlDoc.documentElement.getElementsByTagName("line");
// read each line
for (var a = 0; a < lines.length; a++) {
// get any line attributes
var colour = lines[a].getAttribute("colour");
var width = parseFloat(lines[a].getAttribute("width"));
var diameter = lines[a].getAttribute("diameter");
var project = lines[a].getAttribute("projectid");
var contract = lines[a].getAttribute("contract");
var comp = lines[a].getAttribute("complated");
var id = lines[a].getAttribute("id_line");
// read each point on that line
var points = lines[a].getElementsByTagName("point");
var pts = [];
var length = 0;
var point = null;
for (var i = 0; i < points.length; i++) {
pts[i] = new g.LatLng(parseFloat(points[i].getAttribute("lng")),
parseFloat(points[i].getAttribute("lat")));
if (i > 0) {
length += pts[i-1].distanceFrom(pts[i]);
if (isNaN(length)) { alert("["+i+"] length="+length+" segment="+pts[i-1].distanceFrom(pts[i])) };
}
bounds.extend(pts[i]);
point = pts[parseInt(i/2)];
var info = "<b> Contract: </b>" + contract + " <br/> <b>Project: </b>" + project +"<br/> <b>Diameter: </b>" + diameter + " <br/> <b>Complated: </b>" + comp + " <hr><br/><a class=\"inline-link-1\" href=\"#\">Change Data</a> <a class=\"inline-link-1\" href=\"#\">Edit</a> >" + id +"" ;
}
// length *= 0.000621371192; // miles/meter
if (comp < 1) {
colorr = '#FA0505' }
if (comp > 0 && comp < 25 ) {
colorr = '#FFA640' }
if (comp > 24 && comp < 50) {
colorr = '#FFFD91' }
if (comp > 49 && comp < 75) {
colorr = '#E8E400' }
if (comp > 74 && comp < 100) {
colorr = '#BFFFAD' }
if (comp == 100) {
colorr = '#0F8500' }
var polyline = new g.Polyline({
map:map,
path:pts,
strokeColor:colorr,
strokeWeight:width,
clickable: true
});
//createClickablePolyline(polyloine, html, label, point, length);
// map.addOverlay(polyline);
google.maps.event.addListener(polyline,'mouseover', function() {
this.setOptions({strokeColor: '#690469' });
this.setOptions({strokeOpacity: 1.0 });
this.setOptions({strokeWeight: 4 });
});
google.maps.event.addListener(polyline,'mouseout', function() {
this.setOptions({strokeColor: colorr });
this.setOptions({strokeOpacity: 1.0 });
this.setOptions({strokeWeight: 4 });
});
var mpenc = new google.maps.InfoWindow();
google.maps.event.addListener(polyline,'click', function(event) {
mpenc.setContent(info, this);
mpenc.setPosition(event.latLng, this);
mpenc.open(map);
});
}
map.fitBounds(bounds);
});
}
It looks like you copied some code and changed it. Why is this commented out?
//createClickablePolyline(polyline, html, label, point, length);
That function is what gets closure on the "data", polyline and infowindow, so they are associated with each other (at least in my versions of this code).
这篇关于从xml谷歌地图获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!