[英]Load lng and lat coordinates into MapQuest from XML file
What I'm trying to do is load coordinates on my MapQuest map from a PHP/XML file. 我想做的是从PHP / XML文件在MapQuest地图上加载坐标。 Here is the whole scenario: My page loads and show the map, then I want to click a button that calls a function. 这是整个场景:我的页面加载并显示地图,然后我想单击一个调用函数的按钮。 In this function I uses AJAX to fetch coordinates from an external file called coor.xml. 在此函数中,我使用AJAX从名为coor.xml的外部文件中获取坐标。 In coor.xml I use PHP to grab Coordinates (Lat and Lng) out of my database and generate a XML file. 在coor.xml中,我使用PHP从数据库中获取坐标(纬度和经度)并生成XML文件。 Then those coordinates gets displayed on my map without reloading the page. 然后这些坐标将显示在我的地图上,而无需重新加载页面。 The problem I have is it doesn't work. 我的问题是它不起作用。 Here is my code: 这是我的代码:
MQA.withModule('shapes', function() {
var line = new MQA.LineOverlay();
var lineCoordinates = "";
var x=xmlDoc.getElementsByTagName("coordinates");
for(var i = 0; i < x.length; i++)
{
var lng = x[i].getElementsByTagName("lng")[0].firstChild.nodeValue;
var lat = x[i].getElementsByTagName("lat")[0].firstChild.nodeValue
if((x.length - 1) == i)
{
lineCoordinates = lineCoordinates + lng + ', ' + lat;
}
else
{
lineCoordinates = lineCoordinates + lng + ', ' + lat + ', ';
}
}
line.setShapePoints([lineCoordinates]);
map.addShape(line);
This is what it should display: 它应显示为:
line.setShapePoints([-27.955591, 25.111084, -27.974998, 26.759033, -29.113775, 26.253662]);
But I get the following error: 但是我收到以下错误:
-Unexpected value NaN,NaN parsing points attribute. -意外值NaN,NaN解析点属性。
-Aq is undefined -Aq未定义
Here is my coor.xml file example: 这是我的coor.xml文件示例:
<?xml version="1.0" encoding="utf-8"?>
<markers>
<coordinates>
<id>1</id>
<lat>-27.955591</lng>
<lng>25.111084</lat>
<text>Position 1</text>
</coordinates>
<coordinates>
<id>2</id>
<lat>-27.974998</lng>
<lng>26.759033</lat>
<text>Position 2</text>
</coordinates>
<coordinates>
<id>3</id>
<lat>-29.113775</lng>
<lng>26.253662</lat>
<text>Position 3</text>
</coordinates>
</markers>
Hope I explained this correctly :-) 希望我正确地解释了这一点:-)
Those shape points work great for me. 这些形状点对我很有用。 Is there a url where we can see this happening? 是否有网址可以看到这种情况?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.