Skip to main content

Creating Google Map that uses Java to retrieve XMl file

1 reply [Last post]
trevrex
Offline
Joined: 2008-08-19
Points: 0

Hello,

I work for a non-profit in San Diego as a GIS Specialist. I have had to teach myself about some scripting to create some dynamic maps, but I am still very limited in my skills, so I have had to explore the internet in order to discover various tutorials and examples that have led me on a positive path.

Right now I am working on a Google Mash-Up that will incorporate over 14,000 records, which will appear as separate markers that will have pop-up info bubbles with additional info inside (using html), once the marker is clicked.

Here is the XML script example that is used in the tutorial I am following:

...and this is how it looks when the file is retrieved by the java script and mapped: http://econym.googlepages.com/example_map3.htm

This is the java script that creates the Google Map. I have emboldened the section of the script that retrieves the data and parses it to create the markers:

Google Maps

JavaScript must be enabled in order for you to use Google Maps.
However, it seems JavaScript is either disabled or not supported by your browser.
To view Google Maps, enable JavaScript by changing your browser options, and then
try again.

//' + name + '';
i++;
return marker;
}

// This function picks up the click and opens the corresponding info window
function myclick(i) {
GEvent.trigger(gmarkers[i], "click");
}

// create the map
var map = new GMap2(document.getElementById("map"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.setCenter(new GLatLng( 37.251699,-119.604315), 7);

// Read the data from testXML2blackpoolformat.xml
var request = GXmlHttp.create();
request.open("GET", "testXML2blackpoolformat.xml", true);
request.onreadystatechange = function() {
if (request.readyState == 4) {
var xmlDoc = GXml.parse(request.responseText);
// obtain the array of markers and loop through it
var markers = xmlDoc.documentElement.getElementsByTagName("ConnectoryRecord");

for (var i = 0; i < markers.length; i++) {
// obtain the attribues of each marker
var lat = parseFloat(markers[i].getAttribute("lat"));
var lng = parseFloat(markers[i].getAttribute("lng"));
var point = new GLatLng(lat,lng);
var html = markers[i].getAttribute("html");
var label = markers[i].getAttribute("label");
// create the marker
var marker = createMarker(point,label,html);
map.addOverlay(marker);
}
// put the assembled side_bar_html contents into the side_bar div
document.getElementById("side_bar").innerHTML = side_bar_html;
}
}
request.send(null);
}

else {
alert("Sorry, the Google Maps API is not compatible with this browser");
}
// This Javascript is based on code provided by the
// Blackpool Community Church Javascript Team
// http://www.commchurch.freeserve.co.uk/
// http://econym.googlepages.com/index.htm

//]]>

Here is my delima--
This is the xml format that I need to use because it can accept the rest of my excel file and loop it through the 14,000+ records to create a functioning xml file. This is just a sample (2 records) of the larger file:

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>

-117.03683
32.944505
1
$2.95 Guys
13750 Stowe Drive
Poway
CA
92064
White
Technical Services
http://connectory.com/search/profile_view.aspx?connectoryId=1

-117.272843
33.13337
2
(GLDS) Great Lakes Data Systems
5954 Priestly Drive
Carlsbad
CA
92008
Orange
Technology
http://connectory.com/search/profile_view.aspx?connectoryId=2

This is the tutorial where I found the formatting techniques to successfully create the large xml file that will format/convert my excel file properly: http://www.mrexcel.com/tip064.shtml

These variables should appear as html in the info bubble:

2
(GLDS) Great Lakes Data Systems
5954 Priestly Drive
Carlsbad
CA
92008
Technology
http://connectory.com/search/profile_view.aspx?connectoryId=2

The "Marker" variable instructs Google Maps to label the marker with a particular color. I will be so grateful to the person(s) that helps me get through this wall that I have been hitting for a long time. It's very difficult without having the luxury of peers who know about these types of issues.

Thank you!!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
dajohnson1s
Offline
Joined: 2008-08-27
Points: 0

Not sure if you have figured this out yet since it has been almost 10 days.

Anyway if you look at what Mike has done with the tutorial there is a loop there that first opens the xml file, then loops through each of the tags. From there it looks at the tag and incorporates all that information and essentially builds the marker.

for (var i = 0; i < markers.length; i++) {
// obtain the attribues of each marker
var lat = parseFloat(markers.getAttribute("lat"));
var lng = parseFloat(markers.getAttribute("lng"));
var point = new GLatLng(lat,lng);
var html = markers.getAttribute("html");

<-- loop will be added her to look through the what i want to add
it shouldnt be too difficult

var label = markers.getAttribute("label");
// create the marker
var marker = createMarker(point,label,html);
map.addOverlay(marker);
}

OR

I had found this useful.
http://www.xml.com/pub/a/2005/08/10/google-maps.html?page=3

not so much for the demo, but for the comments at the end. I believe there is somebody has commented exactly what you are trying to do.

Hope this helps
Dan

oh, try to post here if you have any questions.
http://groups.google.com/group/Google-Maps-API

there is many tutorials and the docs are very helpful.