views:

420

answers:

4

Hello,

I am trying to add a link into the pop-up text bubble of a marker in Google Maps through the API. I have successfully run the below code:

echo '<marker lat="43.91892" lng="-78.89231" html="Albertus Magnus College&lt;br&gt;Link to Admissions" label="Albertus Magnus College" />';

But once I actually try to add the link it fails. Like this:

echo '<marker lat="43.91892" lng="-78.89231" html="Albertus Magnus College&lt;br&gt;&lt;a href='http://www.albertus.edu/admission/index.shtml'&amp;gt;Admissions&amp;lt;\/a&amp;gt;" label="Albertus Magnus College" />';

Does anyone know how to successfully write this code? I am writing it into PHP because I have some other functionality that won't let me just write it in XML.

Update: I got it to work like this for some reason...

$window2a_url = '&lt;a href=&apos;http://www.albertus.edu/admission/index.shtml&amp;apos;&amp;gt;Admissions';
echo '<marker lat="41.331304" lng="-72.921438" html=" Albertus Magnus College&lt;br&gt;';
echo $window2a_url;
echo '" label="Albertus Magnus College" />';

I had to escape the apostrophes... If anyone has a more elegant solution, I am all ears!

+1  A: 

Seems you are putting an apostrophe (') inside the string. You should use an escape character (may be "\", I don't know PHP's syntax) near the apostrophe.

friol
for some reason when I tired that I still got an error. But you were right about the "\" being PHP's escape character.
JoshFinnie
A: 

what the other chap said.

try:

echo '<marker lat="43.91892" lng="-78.89231" html="Albertus Magnus College&lt;br&gt;&lt;a href=\'http://www.albertus.edu/admission/index.shtml\'&amp;gt;Admissions&amp;lt;\/a&amp;gt;" label="Albertus Magnus College" />';
benlumley
A: 

The problem is as friol indicates that you end the echo using an apastophe in the link, the code below should work because I escaped the apastrophe (' to \')

echo '<marker lat="43.91892" lng="-78.89231" html="Albertus Magnus College<br><a href=\'http://www.albertus.edu/admission/index.shtml\'&gt;Admissions&lt;/a&gt;" label="Albertus Magnus College" />';
Pim Jager
+1  A: 

This is the answer:

$window2a_url = '&lt;a
href=&apos;http://www.albertus.edu/admission/index.shtml&amp;apos;&amp;gt;Admissions';
echo '<marker lat="41.331304" lng="-72.921438" html=" Albertus Magnus College&lt;br&gt;';
echo $window2a_url;
echo '" label="Albertus Magnus College" />';

I had to escape the apostrophes...

JoshFinnie