Jump to content

Recommended Posts

Hi,

 

I need to get some lat and lon for a google map from an button being clicked.

 

<?php $grid = '<a href="#" onclick="return false" onmousedown="javascript:toggleViewMap(\'google_map\');"><img src="images/btn-viewMap.gif" border="0" alt="'. $lat . ',' . $lon . '"></a>'; } else { $grid = '<img src="images/no_map.png" width="150" height="100" border="0"/>';} ?> 

 

I load some buttons on the form with different lat lon for a location of a shop.

Then when I click the button I want the lat lon loaded in a google map.

<div id="google_map">
<div align="right" style="padding:4px; background-color:#D2F0D3;"><a href="#" onclick="return false" onmousedown="javascript:toggleViewMap('google_map');">close map</a></div>
<?php echo'<iframe width="550" height="300" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps/api/staticmap?center='. $lat .',' . $lon . '&zoom=12&markers=color:red|label:B|' .$lat . ',' . $lon . '&size=550x300&sensor=false">">';?></iframe>
<div align="left" style="padding:4px; background-color:#D2F0D3;"><a href="#" onclick="return false" onmousedown="javascript:toggleViewMap('google_map');">close map</a></div>
    </div>

 

With  the code I have now I always get the same lat lon. How can I read the correct lat lon?

 

Link to comment
https://forums.phpfreaks.com/topic/242124-put-variables-in-img-src/
Share on other sites

they are in my database.

 

<?php
$sql = mysql_query("SELECT * FROM shops WHERE type='bookshop'"); 
while($row = mysql_fetch_array($sql)) { 

$id = $row["id"];
$name = $row["name"];
$address = $row["address"];
$telephone = $row["telephone"];
if ($row["website"]){
	$website = $row["website"] ;
}
$rating = $row["rating"];
$lat = $row["lat"];
$lon = $row["lng"]; ?>

And is this the following code  executed within the while loop?

<div id="google_map">
<div align="right" style="padding:4px; background-color:#D2F0D3;"><a href="#" onclick="return false" onmousedown="javascript:toggleViewMap('google_map');">close map</a></div>
<?php echo'<iframe width="550" height="300" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps/api/staticmap?center='. $lat .',' . $lon . '&zoom=12&markers=color:red|label:B|' .$lat . ',' . $lon . '&size=550x300&sensor=false">">';?></iframe>
<div align="left" style="padding:4px; background-color:#D2F0D3;"><a href="#" onclick="return false" onmousedown="javascript:toggleViewMap('google_map');">close map</a></div>
    </div>

If you place it after the while loop then only last $lat and $lon values will be used.

There is not the problem. All the buttons have the right lat and lon in the alt of the image.

<?php $grid = '<a href="#" onclick="return false" onmousedown="javascript:toggleViewMap(\'google_map\');"><img src="images/btn-viewMap.gif" border="0" alt="'. $lat . ',' . $lon . '"></a>'; } else { $grid = '<img src="images/no_map.png" width="150" height="100" border="0"/>';} ?> 

 

The question is how do I pass them on to the code which opens the google map.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.