开发者

selecting element from xml file

my code is showing all the addresses of shops.xml file. but i want to show just that address (in shops.php)on google map that matched with the inputted address

shops.xml file:

<shops>
<shop>
<name>Galaxy</name>
<address>72 Callander Road, Noble Park</address>
</shop>
<shop>
<name>Home</name>
<address>7 Close Avenue, Dandenong </address>
</shop>
</shops>

shop.htm:

<body>
<form> 
Ente Address: <input type="text" name="address" size="40" /> 
<input name="submit" type = "button" onClick = "load()" value = "Search"  /> 
</form>

<div id="map" style="width: 500px; height: 400px"></div> 
<div id="info"> </div>

shop.js

function load()
  {
    var  map = new GMap2(document.getElementById("map"));          
     map.setCenter(new GLatLng(-37.816667,144.966667), 10);      
     map.addControl(new GSmallMapControl());
     map.addControl(new GMapTypeControl());

    var  geocoder = new GClientGeocoder();

  GDownloadUrl("shops.xml", function(data) {
      var addr =document.getElementsByName['address']; 
      var xml = GXml.parse(data);
     var  shop = xml.documentElement.getElementsByTagName("shop");
      for (var i = 0; i < shop.length; i++) {
      var   addre= shop[i].getElementsByTagName("address");
        addre = addre[0].childNodes[0].nodeValue;
        if(addre==addr)
        var address=addre;
        geocoder.getLocations(address, addToMap);}
    });   
   }


function addToMap(response)
  {
  place = response.开发者_Go百科Placemark[0];
  point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);

  function createMarker(point,address)
   {    
   var marker = new GMarker(point);    
   GEvent.addListener(marker, "click", function() 
   {    
    map.openInfoWindowHtml(point, address);    
   });    
   return marker; 
   } 
   map.addOverlay(createMarker(point, response.name)); 
  }


I think you forget to put condition in this function of matching the address.

-> GDownloadUrl ... in this you have to check condition wheather it is matching the xml address.
->take your value in js variable like var addr =document.getElementsByName['adr'];
-> than have to pass in geocoder.getLocations(address, addToMap);

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜