How convert address to Lat and Lng from an XML file?

zaksampson

New Member
i saw your example of the geocoder and work great, but im building the map from a XML file, how can i use geocoder with xml.\[code\]<script type="text/javascript">var geocoder = new google.maps.Geocoder();var address = "new york";geocoder.geocode( { 'address': address}, function(results, status) {if (status == google.maps.GeocoderStatus.OK) { var latitude = results[0].geometry.location.lat(); var longitude = results[0].geometry.location.lng(); alert(latitude); } }); </script>\[/code\]this is my actual code.\[code\]<script type="text/javascript" src="https://maps.google.com/maps/api/js?sensor=false"></script><script type="text/javascript" src="http://stackoverflow.com/questions/11385832/jquery-1.4.1.min.js"></script><meta name="viewport" content="initial-scale=1.0, user-scalable=no" /><style type="text/css"> #map { height: 70% }</style><apputil:css/><script type="text/javascript">var myIcons = [];myIcons['0'] = 'images/oneclick_flag_green.png';myIcons['1'] = 'images/oneclick_flag_yellow.png';myIcons['2'] = 'images/oneclick_flag_brown.png';myIcons['3'] = 'images/oneclick_flag_orange.png';myIcons['4'] = 'images/oneclick_flag_red.png';myIcons['5'] = 'images/oneclick_flag_blue.png';myIcons['6'] = 'images/oneclick_flag_gray.png';$(document).ready(function() { var myLatLng = new google.maps.LatLng(17.74033553, 83.25067267); MYMAP.init('#map', myLatLng, 11); MYMAP.placeMarkers('gmaps/markers.xml');});var MYMAP = { map: null, bounds: null}MYMAP.init = function(selector, latLng, zoom) { var myOptions = { zoom:zoom, center: latLng, mapTypeId: google.maps.MapTypeId.ROADMAP } this.map = new google.maps.Map($(selector)[0], myOptions); this.bounds = new google.maps.LatLngBounds();}MYMAP.placeMarkers = function(filename) { $.get(filename, function(xml){ $(xml).find("marker").each(function(){ var name = $(this).find('name').text(); var address = $(this).find('address').text(); // create a new LatLng point for the marker var lat = $(this).find('lat').text(); var lng = $(this).find('lng').text(); var icontype = $(this).find('icon').text(); var point = new google.maps.LatLng(parseFloat(lat),parseFloat(lng)); // extend the bounds to include the new point MYMAP.bounds.extend(point); var marker = new google.maps.Marker({ position: point, icon: myIcons[icontype], map: MYMAP.map }); var infoWindow = new google.maps.InfoWindow(); var html='<strong>'+name+'</strong.><br />'+address; google.maps.event.addListener(marker, 'click', function() { infoWindow.setContent(html); infoWindow.open(MYMAP.map, marker); }); MYMAP.map.fitBounds(MYMAP.bounds); }); });}</script>\[/code\]`the xml file look like\[code\]<markers> <marker> <name>Kenny</name> <address>Suipacha 400, buenos aires, argentina.</address> <icon>0</icon> </marker></markers>\[/code\]but is to much work get coordinates manualy.Thanks !
 
Back
Top