如何在地图上显示从XML获取经度和纬度值的位置 [英] How to show location on a map taking longitude and latitude values from XML

查看:193
本文介绍了如何在地图上显示从XML获取经度和纬度值的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个XML条目,它需要从PHP表单中获取地理位置。我想将这些值显示为HTML中的映射:

This is an XML entry and it takes geolocation from PHP form. I want to display those values as a map in HTML:

 <entries>
   <entry>
   <name>Anny</name>
   <email>anny1@hotmail.com</email>
   <place>Fridays</place>
   <comment>Very Good</comment>
   <food>Jack Daniels Burger</food>
   <kitchen>American</kitchen>
   <rating>5</rating>
   <latitude>34.7618259</latitude>
   <longitude>33.0283905</longitude>
   <picture/>
   </entry>
</entries>


推荐答案

您如何生成此XML?我假设你使用PHP来生成它。
这里通过JavaScript来实现,假设您使用的是Google Maps API。

how are you generating this XML? I am assuming you use php to generate it. This here will do it via JavaScript, assuming you're using google-maps API.

也许这可以让您开始:

 var xml = "your xml file"          
     markers = xml.documentElement.getElementsByTagName("marker");
    for (var i = 0; i < markers.length; i++) {
      var name = entries[i].getAttribute("name"); 
      var email = entries[i].getAttribute("email");
      var place ..... an so on
  var lat = entries[i].getAttribute("latitude");
  var lng = entries[i].getAttribute("longitude");

  //the creation of point
  point = new google.maps.LatLng(
          lat,
          lng);
    //create actual marker 
  marker = new google.maps.Marker({
    map: map,
    position: point,
     }); 

创建信息窗口:

to create the info window:

 infoWindow = new google.maps.InfoWindow;
var html =  name + "&nbsp;" + email + '&nbsp;' place ; //+ ... whatever else 

bindInfoWindow(marker, map, infoWindow, html);

function bindInfoWindow(marker, map, infoWindow, html) {
      google.maps.event.addListener(marker, 'click', function() {
          infoWindow.close();
        infoWindow.setContent(html);
        infoWindow.open(map, marker, html);
        map.setCenter(marker.getPosition()); // this will center the map on the clicked marker

      });
    }

希望这有助于帮助

这篇关于如何在地图上显示从XML获取经度和纬度值的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆