Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-17-2009, 02:55 PM   PM User | #1
Jynn
New Coder

 
Join Date: Jun 2009
Posts: 16
Thanks: 2
Thanked 1 Time in 1 Post
Jynn is an unknown quantity at this point
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
Jynn is offline   Reply With Quote
Old 06-17-2009, 07:24 PM   PM User | #2
lostprophetsie
New to the CF scene

 
Join Date: Jun 2009
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
lostprophetsie is an unknown quantity at this point
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
lostprophetsie is offline   Reply With Quote
Old 06-18-2009, 11:44 AM   PM User | #3
Jynn
New Coder

 
Join Date: Jun 2009
Posts: 16
Thanks: 2
Thanked 1 Time in 1 Post
Jynn is an unknown quantity at this point
Hi lostprophetsie,

Thanks for ur help. But after putting the code, all my markers disappeared.
Jynn is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:04 AM.


Advertisement
Log in to turn off these ads.