Javascript 从XML文件将lng和lat坐标加载到MapQuest中
我试图做的是从PHP/XML文件加载MapQuest地图上的坐标。 以下是整个场景: 我的页面加载并显示地图,然后我想单击调用函数的按钮。在这个函数中,我使用AJAX从一个名为coor.xml的外部文件中获取坐标。在coor.xml中,我使用PHP从数据库中获取坐标(Lat和Lng),并生成一个xml文件。然后这些坐标将显示在我的地图上,而无需重新加载页面。 我的问题是它不起作用。 这是我的密码:Javascript 从XML文件将lng和lat坐标加载到MapQuest中,javascript,php,xml,mapquest,Javascript,Php,Xml,Mapquest,我试图做的是从PHP/XML文件加载MapQuest地图上的坐标。 以下是整个场景: 我的页面加载并显示地图,然后我想单击调用函数的按钮。在这个函数中,我使用AJAX从一个名为coor.xml的外部文件中获取坐标。在coor.xml中,我使用PHP从数据库中获取坐标(Lat和Lng),并生成一个xml文件。然后这些坐标将显示在我的地图上,而无需重新加载页面。 我的问题是它不起作用。 这是我的密码: MQA.withModule('shapes', function() {
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);
但我得到了以下错误:
-意外值NaN,NaN解析点属性
-Aq未定义
下面是我的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>
1.
-27.955591
25.111084
位置1
2.
-27.974998
26.759033
位置2
3.
-29.113775
26.253662
位置3
希望我能正确解释:-)这些形状点对我来说非常有用。有一个我们可以看到这种情况的url吗?您好。我会在早上给你发一个链接,因为我知道这有点晚了。准确地说,晚上23点48分:-)
<?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>