Outputting markers to Google Map

Ah I got it, but I don’t need it.

I went into the database and added a type field, then added bar to it, and outputted the xml as below

<?xml version="1.0"?>

-<markers>

<marker type="bar" lng="2.078728" lat="41.394768" address="Barcelona"/>

</markers>

Then un commented the type option on the main page and the marker appeared.

But its not something I need, so ideally I don’t need it to be considered on the main page to output the marker.

To revert it all back to your suggestion, I put it all back as it was and it worked fine as below.

result2.php

ah i wondered if that was a problem, but i thought that it would just output a standard marker without it. If it works with it you can just hardcode it into the xml output type=‘hotel’ or something. Then in the future if you want to output different markers you can use the type variable to change them type=‘restuarant’

So in the php just add

> $newnode->setAttribute("type", utf8_encode('hotel'));

I changed it to hotel so it makes more sense to what you are doing. You’ll have to change the custom icon name as well if you do that. Prob don’t need to utf8 encode the above but won’t be an issue.

Great, I’ll add that in.

One more thing, its lucky that as an example I have picked Barcelona as it shows clearly on the map anyway, but as I have now also added name as a field, I thought the name may appear next to the marker, because some of the other regions wont have the name already on the map if you know what I mean.

this part of the code

 function bindInfoWindow(marker, map, infoWindow, html) {
      google.maps.event.addListener(marker, 'click', function() {
        infoWindow.setContent(html);
        infoWindow.open(map, marker);
      });
    }

tells it to open an info window when you click the marker. It should load the ‘html’ from the variable which is set further up the code

var html = '<b>' + address + '</b> <br/>';

You can change the ‘click’ to ‘hover’ (i think - been a while since i tried it) so the user just hovers over and a window opens (can get messy though with lots of markers). And the html can be added to so you can add whatever you like an image or a title etc. If you want to get fancy you could expand your database to pick up the hotels lat/lng and the image of the hotel and output that on the map. One step further and you could have the results as a big map instead of the list view… something for the future perhaps.

i still can’t see the marker is it live yet?

Ye lucky you asked, because I can see the marker and so I asked a colleague and he cant see it on his. So there something still wrong, and why I wondered too is because I just added lat and lng to Bilbao and its not coming up

ah try changing

downloadUrl('phpsqlajax_genxml.php?selectCountry='+scountry, function(data) {

the live one is

downloadUrl(‘phpsqlajax_genxml.php?selectCountry=’, function(data) {

which is missing the variable

ah there you go, but lol the markers are a bit off, will have to sort that out but at least I got 2 now.

Thanks Noppy

cool glad you got it sorted. Remember to change the hardcoded ‘selectCountry’ variable to = the GET variable or it won’t change the output.

Also at the moment the font color is white on the info bubbles

#mapLarge {
    color: #fff;

in styles.css

Also and this is EXTREMELY important you need to escape any variables before using in the mysql query. At the very least do

$selectCountry = mysql_real_escape_string($_GET['selectCountry']);

http://php.net/manual/en/function.mysql-real-escape-string.php

but ideally look at changing to mysqli or prepared statements.

hth

Thank you very much Noppy. you have been brilliant, and the way you came back on the Tuesday was fantastic, this is why I only use this forum, the help on here is outstanding, and will try and help myself a bit more where I can.

Cheers

no worries. Glad i could help. Most of the time i am the one asking others for help so it’s good i could help someone.

I’m certainly no expert on google maps but i’ve done a few bit. If you want to take a look at these pages i’ve done you can get an idea of a few possiblities for expanding your map if you need to

http://www.goodbeachguide.co.uk/search-map?beach_name=beach&postcode=&radius=10&wq_grade=projected+Excellent&lifeguards=&dog_restrictions=&page=&results=

http://www.mcsuk.org/sightings/map/index.php

Both of these use the variables to output from databases in the same way as above but i’ve added more variables you can filter results etc.

good luck.

excellent yes looks great.

Im trying to work out why my bubbles aren’t bigger, yours are working well.

Those markers of mine are way of mark, so will have to find a way of knowing what the scale of the map is as im collecting them to then have them out put correctly in my map.

i forced the bubbles to be bigger with

var infoWindow = new google.maps.InfoWindow({ maxWidth: 100 });

could try that and see if it works for you.
The scale of the map shouldn’t matter i think your lat/lng are wrong in the database. If you put it into gmaps https://www.google.co.uk/maps/place/41°16’45.4"N+11°13’57.3"W/@42.9382254,-9.3305114,5.46z/data=!4m2!3m1!1s0x0:0x0 it still ends up in the sea.

barcelona should be more like lat:41.343275 lng:2.087402 :smile:

lol ye not the best is it advertising Barcelona in the ocean…

Can you refresh and see if they are on point now, only 2 for the time being

looks pretty good to me now.

phew, finally got there. There a slight issue with the text area in the bubble in IE, fine in Mozilla though, but at least now I can crack on.

Will take a look at yours again if you don’t mind

feel free. Still a few rough edges in mine to be honest, let me know if you spot anything not working right :slight_smile:

I’m still trying to work out how to do clustering when there are too many markers in one spot but haven’t got there yet.

Oh right, ye clustering…

I will bookmark yours then and use it as a yard stick, thanks again I have enjoyed this project

with a bit of help from @fretburner I now have a working example of clustering if you are interested…

http://www.mcsuk.org/sightings/map/cluster.php

hope it’s useful