Jump to content

Recommended Posts

Im doing for google maps which is used using php and mysql and my pin points showing on the map disappear.

 

Well, this could be due to a million different things.  Are you using Firebug for Firefox?  It will help you to drill down any formatting errors within javascript and such.

 

The code you initially posted, is that within a 'createMarker()' sort of function?  Can you post that function and any related code.  Mentioning this was within Google Maps is the kind of info you really need to include at the beginning, and may not be a PHP issue at all.

I don't think so, heres more of the code:


// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
  // ADD TO XML DOCUMENT NODE
  echo '<marker ';
  echo 'name="' . parseToXML($row['name']) . '" ';
  echo 'address="' . parseToXML($row['address']) . '" ';
  echo 'lat="' . $row['lat'] . '" ';
  echo 'lng="' . $row['lng'] . '" ';
  echo 'type="' . $row['type'] . '" ';
  echo '/>';
}

 

No im using the safari browser.

You can't put HTML tags inside of HTML tags. 

 

Adding line breaks to this won't do any good.

 

If you wish to add line breaks so the HTML source is prettier for some reason, use "\n":

 

  echo 'name="' . parseToXML($row['name']) . '" ' . "\n";

 

I did that but the ouput still remains the same, it doesnt have a line break?

  echo 'name="' . parseToXML($row['name']) . '" ' . "\n";

 

And yeah MrMarcus You did give me another way, but when I saw your reply i already got it all working with the google maps following their tutorial. I just want to know how to style it?

I did that but the ouput still remains the same, it doesnt have a line break?

echo 'name="' . parseToXML($row['name']) . '" ' . "\n";

 

The styling does not go in there.  As was stated earlier, you cannot put HTML within HTML.  That line of code is part of a block of code that is how your map reads the markers to be displayed:

 

// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
  // ADD TO XML DOCUMENT NODE
  echo '<marker ';
  echo 'name="' . parseToXML($row['name']) . '" ';
  echo 'address="' . parseToXML($row['address']) . '" ';
  echo 'lat="' . $row['lat'] . '" ';
  echo 'lng="' . $row['lng'] . '" ';
  echo 'type="' . $row['type'] . '" ';
  echo '/>';
}

 

The above outputs like so:

 

<marker name="something" address="something" lat="something" lng="something" type="something"/>

 

And you cannot put styling within.

 

From there, the while() loop will iterate through all available 'markers' in the database, and generate the corresponding number of markers that will then be parsed by further code to be displayed on the map.

 

What exactly are you trying to style?  The InfoWindow when you click on a marker?  Please be specific and show some code (you should have a [javascript] function that creates the markers, ie. CreateMarker(), or something similar).

Yeah the information in the info window. I tried the <br/> in the javascript and it worked. So im guessing I can style using javascript? How can I give the javascript some sort of ID so I can style it in my css?


function createMarker(point, name, address, type) {
      var marker = new GMarker(point, customIcons[type]);
      var html = "<b>" + name + "</b> <br/><br/>" + address;
      GEvent.addListener(marker, 'click', function() {
        marker.openInfoWindowHtml(html);
      });
      return marker;
    }

Yeah the information in the info window. I tried the <br/> in the javascript and it worked. So im guessing I can style using javascript? How can I give the javascript some sort of ID so I can style it in my css?


function createMarker(point, name, address, type) {
      var marker = new GMarker(point, customIcons[type]);
      var html = "<b>" + name + "</b> <br/><br/>" + address;
      GEvent.addListener(marker, 'click', function() {
        marker.openInfoWindowHtml(html);
      });
      return marker;
    }

 

Yes, that's it.  Do all your styling within there.

 

Have you tried it?  Create a class/ID and swap out the <b> for <span class="your_class"> and see what happens.

 

I just noticed this tutorial is for Gmaps V2.  Version 2 is dated, and if not already, will soon be deprecated.  If you plan on working with Google Maps in the future on other projects, get rid of V2 immediately and do not waste any more time.  Move to V3.  I strongly, strongly recommend you do so.  It's faster, cleaner, and more scalable.  The example I provided you in the other thread was V3.  Mess around with my example map.  You can use the exact same db table, and I believe my code was already setup using the same fields as your example.

Ok I did that but the map totally disapears?

var html = "<span class="mapinfo">" + name + "</b> <br/><br/>" + address;

 

My mistake.  Either replace the double-quotes with single-quotes or escape the double-quotes.  And you didn't replace the closing </b>.  You know basic HTML, correct?

 

var html = "<span class='mapinfo'>" + name + "</b> <br/><br/>" + address;

Thanks Mate, really appreciate it. Would It be possible for me to add a image in there too? in the info window.

 

So add the url of the images in my table and then somehow code it in the php file?

 

Yes, you can add pretty much anything you want in there.  Only one way to find out... try it.

 

var html = "<img src='" + image + "'/> <span class='mapinfo'>" + name + "</span> <br/><br/>" + address;

 

You must now add 'image' to your XML markup:

 

// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
  // ADD TO XML DOCUMENT NODE
  echo '<marker ';
  echo 'name="' . parseToXML($row['name']) . '" ';
  echo 'address="' . parseToXML($row['address']) . '" ';
  echo 'lat="' . $row['lat'] . '" ';
  echo 'lng="' . $row['lng'] . '" ';
  echo 'type="' . $row['type'] . '" ';
  echo 'image"'. $row['image'] .'" ';
  echo '/>';
}

 

And, of course, have the URL to the image in the db table `markers` for each record.  Move/style the image within the createMarker() function to suit your needs.  Add width/height and so on.

I added the image codes in the javascript and php, but the markers have now disappeared?

 

Do you have images in the database table `markers`?  You have added the column `image`?  If so, post what an example image URL is that you have in the table.

Yeah I have added 1 url for 1 entry and wanted to see if it works. Heres the image of the markers table:

 

Heres the line of code in javascript:

var html = "<img src='" + image + "'/><span class='mapinfo'>" + name + "</span> <br/><br/>" + address;

 

And the PHP:


// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
  // ADD TO XML DOCUMENT NODE
  echo '<marker ';
  echo 'name="' . parseToXML($row['name']) . '" ';
  echo 'address="' . parseToXML($row['address']) . '" ';
  echo 'lat="' . $row['lat'] . '" ';
  echo 'lng="' . $row['lng'] . '" ';
  echo 'type="' . $row['type'] . '" ';
  echo 'image="' . $row['image'] . '" ';
  echo '/>';
}

post-130660-13482403511772_thumb.png

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.