clausowitz Posted July 16, 2011 Share Posted July 16, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/242124-put-variables-in-img-src/ Share on other sites More sharing options...
wildteen88 Posted July 16, 2011 Share Posted July 16, 2011 Where are you defining the $lat and $lon variables? Quote Link to comment https://forums.phpfreaks.com/topic/242124-put-variables-in-img-src/#findComment-1243448 Share on other sites More sharing options...
clausowitz Posted July 16, 2011 Author Share Posted July 16, 2011 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"]; ?> Quote Link to comment https://forums.phpfreaks.com/topic/242124-put-variables-in-img-src/#findComment-1243449 Share on other sites More sharing options...
wildteen88 Posted July 16, 2011 Share Posted July 16, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/242124-put-variables-in-img-src/#findComment-1243450 Share on other sites More sharing options...
clausowitz Posted July 16, 2011 Author Share Posted July 16, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/242124-put-variables-in-img-src/#findComment-1243451 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.