...

View Full Version : Hyperlink in google map's infowindow?



Jynn
06-17-2009, 03:55 PM
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:

//<![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

<?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


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

Any idea? Thanks:):):)

lostprophetsie
06-17-2009, 08:24 PM
Hi Jynn,

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


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 :D

Jynn
06-18-2009, 12:44 PM
Hi lostprophetsie,

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum