Reputation: 617
I'm trying to create a simple php code when the user clicks on the link of a stadium it will show the location of stadium using google map. However, when I try and clicked on the stadium it does not show the exact location. I've checked the code many times and I don't know where is the problem.
This is the code of the map
<html>
<?php
session_start();
include('dbconn.php');
$id=$_GET['id'];
$sql=mysql_query("SELECT stadium, city, state FROM fixtures where fixtures_id='" .$id ."'");
$row= mysql_fetch_array($sql);
$stadium = urlencode($row['stadium']);
$city = urlencode($row['city']);
$state = urlencode($row['state']);
$place = "$city,+$stadium,+$state";
?>
<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0"
marginwidth="0" src="https://maps.google.com/maps?
f=q&source=s_q&hl=en&geocode=&q=<?php echo $place; ?>
&aq=0&ie=UTF8&hq=&hnear=<?php echo $place; ?>
&t=m&iwloc=&output=embed"></iframe>
</html>
This is how i store the stadium, city and state inside my database
And this is the output which is incorrect
Upvotes: 1
Views: 365
Reputation: 142
Try to store lat and long
here try to make valid address string
$place = "$stadium,+$city,+$state";
Upvotes: 0
Reputation: 1667
It would be easier to store longitude and latitude information in the database, that way you are always sure the correct stadium is shown.
Sometimes the geocoding works better if you add the country name and the place instead of the place only. Depending on the users location, only using the place can go horribly wrong...
Upvotes: 2