Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jun 2009
    Posts
    16
    Thanks
    2
    Thanked 1 Time in 1 Post

    Hyperlink in google map's infowindow?

    Hi guys.. any idea how to put a hyperlink in google map's infowindow?

    Now my infowindow is managed to echo user name and address. What i intend to do is adding a hyperlink at below (inside infowindow) to view_mem.php. I heard it's impossible to add hyperlink inside. Any opinion?

    This is my google map:
    Code:
       //<![CDATA[
    
    	 function load() {
          if (GBrowserIsCompatible()) {
            var map = new GMap2(document.getElementById("map"));
            map.addControl(new GSmallMapControl());
            map.addControl(new GMapTypeControl());
            map.setCenter(new GLatLng(1.37173, 103.847641), 11);
    
    		
            GDownloadUrl("do_view_all.php", function(data) {
              var xml = GXml.parse(data);
              var markers = xml.documentElement.getElementsByTagName("marker");
              for (var i = 0; i < markers.length; i++) {
                var name = markers[i].getAttribute("name");
                var address = markers[i].getAttribute("address");
                var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
                                        parseFloat(markers[i].getAttribute("lng")));
                var marker = createMarker(point, name, address);
                map.addOverlay(marker);
              }
            });
          }
        }
    
        function createMarker(point, name, address) {
          var marker = new GMarker(point);
          //var html = "<b>" + name + "</b> <br/>" + address;
    	  var html = "<b>" + name + "</a></b> <br/>" + address;
          GEvent.addListener(marker, 'click', function() {
            marker.openInfoWindowHtml(html);
    	
          });
          return marker;
        }
        //]]>

    This is the php file to print out the infowindow
    Code:
    <?php
    function parseToXML($htmlStr) 
    { 
    $xmlStr=str_replace('<','&lt;',$htmlStr); 
    $xmlStr=str_replace('>','&gt;',$xmlStr); 
    $xmlStr=str_replace('"','&quot;',$xmlStr); 
    $xmlStr=str_replace("'",''',$xmlStr); 
    $xmlStr=str_replace("&",'&amp;',$xmlStr); 
    return $xmlStr; 
    } 
    
    require("opendb.php");
    
    
    // Select all the rows in the markers table
    $query = "SELECT * FROM profile where 1";
    $result = mysql_query($query);
    if (!$result) {
      die('Invalid query: ' . mysql_error());
    }
    
    header("Content-type: text/xml");
    
    
    
    // Start XML file, echo parent node
    echo '<markers>';
    
    // 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['username']) . '" ';
      echo 'address="' . parseToXML($row['address']) .'" ';
      echo 'lat="' .  $row['lat'] . '" ';
      echo 'lng="' . $row['lng'] . '" ';
      echo '/>';
    }
     
    
    // End XML file
    echo '</markers>';
    
    ?>
    I tried to do something like this in my echo '<marker '; But it doesn't work

    Code:
    echo 'link="'.parseToXML"<a href= 'view_mem.php"."?user_id=".$row['user_id']."'>View Profile</a>";
    Any idea? Thanks

  • #2
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hi Jynn,

    Try the following in your javascript code for the map, just replace your createMarker function with the following:

    Code:
    function createMarker(point, name, address, user_id) {
          var marker = new GMarker(point);
          //var html = "<b>" + name + "</b> <br/>" + address;
    	  var html = "<b>" + name + "</a></b> <br/>" + address +"<br /><a href='view_mem.php??user_id=" + user_id +"'>View Profile</a><br /><b>"+ id +"</b>" ;
          GEvent.addListener(marker, 'click', function() {
            marker.openInfoWindowHtml(html);
    	
          });
    You may need to make a few changes depending on your variable names, I tried my best with them
    Last edited by lostprophetsie; 06-17-2009 at 07:26 PM. Reason: spelling

  • #3
    New Coder
    Join Date
    Jun 2009
    Posts
    16
    Thanks
    2
    Thanked 1 Time in 1 Post
    Hi lostprophetsie,

    Thanks for ur help. But after putting the code, all my markers disappeared.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •