Skip to content Skip to sidebar Skip to footer

How To Show Location On A Map Taking Longitude And Latitude Values From Xml

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

Solution 1:

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.

maybe this can get you started:

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

      });
    }

hopefully some of this can help

Solution 2:

You want to show these LatLong points as markers, I assume. Here is how to do that in google maps.

var myLatlng = new google.maps.LatLng(-25.363882,131.044922);

var marker = new google.maps.Marker({
 position: myLatlng,
 title:"Hello World!"
});

// To add the marker to the map, call setMap();
marker.setMap(map);

See more at https://developers.google.com/maps/documentation/javascript/markers

Similarly you can do it in mapbox like this

L.mapbox.featureLayer({
// this feature is in the GeoJSON format: see geojson.org// for the full specificationtype: 'Feature',
geometry: {
    type: 'Point',
    // coordinates here are in longitude, latitude order because// x, y is the standard for GeoJSON and many formats
    coordinates: [
      -77.03221142292,
      38.913371603574 
    ]
}).addTo(map);

Post a Comment for "How To Show Location On A Map Taking Longitude And Latitude Values From Xml"