View Full Version : How convert address to Lat and Lng from an XML file?

07-10-2012, 11:15 PM
Hi great users !
im new with javascripts.. and i have a problem using the geocoder from a value of the xml file.

this is my script.

<script type="text/javascript" src="https://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="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% }
<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);

var MYMAP = {
map: null,
bounds: null

MYMAP.init = function(selector, latLng, zoom) {
var myOptions = {
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){
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

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.open(MYMAP.map, marker);

and this is my XML file

<address>Suipacha 400, buenos aires, argentina.</address>

how can i convert the ADDRESS to coordinates and then map it !


07-10-2012, 11:30 PM
erm... I don't think you are using the geocoder at all, at least not in that script.

but anyway. if you know the address in advance you shouldn't be geocoding it to get its location on the fly - the geocoder is designed for dynamic input from user generated variables. geocode the address once, get the lat lng and hard code them into your database or page and use that to place the marker

(y saludos desde montevideo :thumbsup:)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum