Problem Adding Markers From Database

224 views
Skip to first unread message

Tinman

unread,
Jun 10, 2010, 2:53:55 AM6/10/10
to Google Maps JavaScript API v3
Hi.
I have been working on a dynamic map for a game lately and I am trying
to add markers from database entries.
I have mad the database and added a few entries into it, I have also
made a .php file that creates a xml file that the Google Maps API
should be able to collect information from that to add markers onto my
map.

The map is located here: http://www.undergroundrp.com/dev3/map.html
The .php file that creates the .xml file is here:
http://www.undergroundrp.com/dev3/phpsqlajax_genxml.php

The code I am currently using to attempt to collect the xml
information and put it onto the map:

<!--Add Markers From Database Start-->

downloadUrl("phpsqlajax_genxml.php", function(data) {
var xml = parseXml(data);
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var name = markers[i].getAttribute("name");
var description = markers[i].getAttribute("description");
var image = markers[i].getAttribute("icon");
var point = new google.maps.LatLng(
parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var html = "<b>" + name + "</b> <br/>" + description;
var image = 'http://google-maps-icons.googlecode.com/files/'+icon;
var marker = new google.maps.Marker({
map: map,
position: point,
icon: image,
shadow: 'http://google-maps-icons.googlecode.com/files/
shadow.png'
});
bindInfoWindow(marker, map, infoWindow, html);
}
});

<!--Add Markers From Database End-->

But this "destroys" my map, and I have no idea how to do this, I have
no problem with php and sql but when it comes to this Java and Google
Maps API I am really a noob ^^

If anyone got any idea on how I would be able to load this I would be
very greatfull.
Message has been deleted

Davide Cremonesi

unread,
Jun 10, 2010, 4:15:25 AM6/10/10
to Google Maps JavaScript API v3
downloadUrl is not defined.
google.maps.DownloadUrl or GDownloadUrl are part of the v2 API.
Now v3 is loaded by default, so if you want to use v2 APIs you have to
load it explicitly specifying the v=2 in the google maps api URL.

Ciao,
Davide

Tinman

unread,
Jun 10, 2010, 9:06:28 AM6/10/10
to Google Maps JavaScript API v3
Thanks for your reply.
I tried to define it with this code:

function downloadUrl(url,callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;

request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request.responseText, request.status);
}
};

request.open('GET', url, true);
request.send(null);
}

And now the map loads again, but it does not load any markers.
Is there something wrong in the first piece of code maybe?

Thanks again for your reply, getting the downloadUrl defined seems to
have been part of the answer.

Scorpius

unread,
Jun 10, 2010, 10:02:50 AM6/10/10
to Google Maps JavaScript API v3
Looks like you still haven't defined the function doNothing yet.
Just use:
function doNothing() {}

Tinman

unread,
Jun 10, 2010, 10:20:11 AM6/10/10
to Google Maps JavaScript API v3
Thanks, I got that added now, but still no markers are showing up on
the map, I though they might have been invisible but they are not
there at all.

Scorpius

unread,
Jun 10, 2010, 10:43:34 AM6/10/10
to Google Maps JavaScript API v3
Seems you're still missing one more function.

function parseXml( str )
{
if (window.ActiveXObject)
{
var doc = new ActiveXObject('Microsoft.XMLDOM');
doc.loadXML(str);
return doc;
}
else if (window.DOMParser)
{
return (new DOMParser).parseFromString(str, 'text/xml');

Tinman

unread,
Jun 10, 2010, 11:04:43 AM6/10/10
to Google Maps JavaScript API v3
Thanks again for your help, I really appreciate it.

But even after adding this the markers still fail to show up on the
map, I have looked over my code several times also now and I think
everything is defined, and everything seems right, though I am not
very good with the API and Java so its not that easy for me to spot if
anything is actually wrong. (I am more of a php sql guy)

I hope we can figure this thing out, the people in the community I am
in, and myself would love it ;)
Thanks one more time for all the help I am getting!

geoco...@gmail.com

unread,
Jun 10, 2010, 12:00:16 PM6/10/10
to Google Maps JavaScript API v3
On Jun 10, 8:04 am, Tinman <bjo...@gmail.com> wrote:
> Thanks again for your help, I really appreciate it.
>
> But even after adding this the markers still fail to show up on the
> map, I have looked over my code several times also now and I think
> everything is defined, and everything seems right, though I am not
> very good with the API and Java so its not that easy for me to spot if
> anything is actually wrong. (I am more of a php sql guy)
>
> I hope we can figure this thing out, the people in the community I am
> in, and myself would love it ;)
> Thanks one more time for all the help I am getting!

I get a straight javascript error:
Line: 48
Error: 'description' is undefined

Because "description" is undefined in this line:
var html = "<b>" + name + "</b> <br/>" + description;

Then:
Line: 56
Error: 'infoWindow' is undefined

Because that isn't defined either.

-- Larry
> > > > > > > very greatfull.- Hide quoted text -
>
> - Show quoted text -

Tinman

unread,
Jun 10, 2010, 12:05:35 PM6/10/10
to Google Maps JavaScript API v3
Thanks, removing that completely out of the code made the icons
appear, right now only the shadow as thats the only thing that I knew
would work, now I just need to figure out how to load the actual icon
that I want for each marker onto it.

Tinman

unread,
Jun 10, 2010, 12:11:19 PM6/10/10
to Google Maps JavaScript API v3
I actually figured that out and got separate icons loading for my
markers, though the shadows seems to be a bit to the left of where
they should be located but that is something I could fix in a image
editing program.

Now onto my next step, being able to toggle markers depending on what
type they are, if there are anyone in here that knows how just shout
it out, I will be looking into it myself now, I just hope its not as
complicated as the past few things I have been doing ;)

Thanks again to everyone, you have really helped me out a whole lot, I
really appreciate it!

geoco...@gmail.com

unread,
Jun 10, 2010, 12:35:01 PM6/10/10
to Google Maps JavaScript API v3
On Jun 10, 9:11 am, Tinman <bjo...@gmail.com> wrote:
> I actually figured that out and got separate icons loading for my
> markers, though the shadows seems to be a bit to the left of where
> they should be located but that is something I could fix in a image
> editing program.

If you do want infowindows:
http://www.geocodezip.com/undergroundrp_com_mapC.html

I haven't looked at marker categories with v3, but Mike Williams'
tutorial:
http://econym.org.uk/gmap/

has an example for v2 that should be able to be used for the concepts.
http://econym.org.uk/gmap/categories.htm

-- Larry
> > > > - Show quoted text -- Hide quoted text -

Tinman

unread,
Jun 10, 2010, 1:41:26 PM6/10/10
to Google Maps JavaScript API v3
ooh, now that is useful, having info boxes like that could help out
giving a better description of certain things.
I will look into the tutorial you linked, it might work. If I get
something I will post my results here ;)

On 10 Jun, 18:35, "geocode...@gmail.com" <geocode...@gmail.com> wrote:
> On Jun 10, 9:11 am, Tinman <bjo...@gmail.com> wrote:
>
> > I actually figured that out and got separate icons loading for my
> > markers, though the shadows seems to be a bit to the left of where
> > they should be located but that is something I could fix in a image
> > editing program.
>
> If you do want infowindows:http://www.geocodezip.com/undergroundrp_com_mapC.html
>
> I haven't looked at marker categories with v3, but Mike Williams'
> tutorial:http://econym.org.uk/gmap/
>
> has an example for v2 that should be able to be used for the concepts.http://econym.org.uk/gmap/categories.htm

Tinman

unread,
Jun 10, 2010, 3:48:14 PM6/10/10
to Google Maps JavaScript API v3
I have attempted to create a way to toggle by types, but it seems the
method used in the http://econym.org.uk/gmap/categories.htm
tutorial is not working in v3 or I am just not able to get it to work,
the later being very possible ;)
I have put up a new map page as I do not want to ruin the other one as
it is working very good right now, the new example map with the
attempted type (category) toggling can be found here:http://
www.undergroundrp.com/dev3/map2.html

I have probably messed up a whole lot of things in that one, but I am
thinking positive as long as the map and icons load at all :p

If anyone has any clue on how to do this, please reply it would be
very appreciated!

geoco...@gmail.com

unread,
Jun 10, 2010, 4:22:41 PM6/10/10
to Google Maps JavaScript API v3
On Jun 10, 12:48 pm, Tinman <bjo...@gmail.com> wrote:
> I have attempted to create a way to toggle by types, but it seems the
> method used in thehttp://econym.org.uk/gmap/categories.htm
> tutorial is not working in v3 or I am just not able to get it to work,
> the later being very possible ;)
> I have put up a new map page as I do not want to ruin the other one as
> it is working very good right now, the new example map with the
> attempted type (category) toggling can be found here:http://www.undergroundrp.com/dev3/map2.html
>
> I have probably messed up a whole lot of things in that one, but I am
> thinking positive as long as the map and icons load at all :p
>
> If anyone has any clue on how to do this, please reply it would be
> very appreciated!

You are close.
Problems:
1. boxclick is local to your initialize function (as are some of your
other functions), the html click handlers execute in the global scope.
2. APIv3 has a different show/hide syntax, it uses the setVisible
method.
3. you need to add the global gmarkers array to your code

http://www.geocodezip.com/undergroundrp_com_map2b.html

Tinman

unread,
Jun 10, 2010, 5:33:35 PM6/10/10
to Google Maps JavaScript API v3
Thanks a billion, I expanded upon it and updated some of my database
entries and it looks very very nice!
http://www.undergroundrp.com/dev3/map2.html

Now I am just on the "pretty-it-up" phase, would anyone know how I
could change the gray background to a color more like the water
(#405357) so that it would look continuous? The outer tiles them selfs
I can fix in a image editing program, but the actual API background I
do not know how to change, I have searched around a little and can
only find text changes from what i understand and not the actual API
bg.

Thanks for all the help!
> ...
>
> les mer »
Reply all
Reply to author
Forward
0 new messages