0

Hi! I am trying to make a small application with google maps!

I have successfully addded few points on the map using xml output to php from mysql database..

function load() {
      var map = new google.maps.Map(document.getElementById("map"), {
        center: new google.maps.LatLng(38.99,22.49),
        zoom: 7,
        mapTypeId: 'roadmap'
      });
      var infoWindow = new google.maps.InfoWindow;

      // Change this depending on the name of your PHP file
      downloadUrl("phpsqlajax_genxml2.php", function(data) {
        var xml = data.responseXML;
        var markers = xml.documentElement.getElementsByTagName("marker");
        for (var i = 0; i < markers.length; i++) {
          var name = markers[i].getAttribute("name");
          var info = markers[i].getAttribute("info");
          var type = markers[i].getAttribute("type");
          var point = new google.maps.LatLng(
              parseFloat(markers[i].getAttribute("lat")),
              parseFloat(markers[i].getAttribute("lng")));
         var html = "<b>" + name + "</b> <br/>" + info;

          var icon = customIcons[type] || {};
          var marker = new google.maps.Marker({
            map: map,
            position: point,
            icon: icon.icon
          });
          bindInfoWindow(marker, map, infoWindow, html);
        }
      });
    }

My problem is that info variable is stored in mysql like this:
firstline<br />secondline<br />thirdiline<br /> .
I managed to do in before i insert the data to my mysql database:
$myinfo = htmlspecialchars($_POST['info']);
$myinfo = str_replace("\n", "<br />", $myinfo);

So, why i click on the point on the map i get this infobox:
NameOFBox
firstline<br />secondline<br />thirdiline<br />

i wanted to get something like this:
NameOFBox
firstline
secondline
thirdline

what am i doing wrong? I understand that <br /> is html code and not java code..however i tried to replace <br /> in the database with \n\n but nothing happened.. i get something like this
NameOFBox
firstline\n\nsecondline\n\nthirdline\n\n

any help?
thanks in advance!

1
Contributor
3
Replies
8
Views
3 Years
Discussion Span
Last Post by christ123
0

i solved it by myself..if you ever face the same problem with me:

i insert the data to the database using:
$myinfo = str_replace("\n", "|||", $myinfo);

and back to the html file where i have the map:

        var array = info.split('|||');
        var html = "<b>" + name + "</b> <br/>" + array[0];
    for (var i=1; i<array.length; i++) {
        html += '<br ></array>' + array[i];
        }
0

problem...after adding:

 for (var i=1; i<array.length; i++) {
html += '<br ></array>' + array[i];
}

works but only 1 marker is shown now..

0

i got my answer again alone :D i is being used in the outter for loop.. using j in the second for solved the problem :D

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.