In my database I have lat/lng values and I'm trying to display markers on a google map. (I have my map coming up ok but can't get the markers going!).
// Selects all the rows in the tester table.
$query = 'SELECT * FROM tester WHERE 1';
$result = mysql_query($query);
if (!$result)
{
die('Invalid query: ' . mysql_error());
}
while ($row = mysql_fetch_assoc($result))
{?>
var marker = new google.maps.Marker({
position: <?php $row['lat']?>, <?php $row['lng']?> ,
map: map,
title:"Hello World!"
});
}
Any help would be great thanks!
Add multiple markers with Info Window to the Google Map. Fetch dynamic marker icons from the database. Change and add custom icon/images to markers. An API key is required to use the Google Maps JavaScript API. You need to specify the API key on API call to authenticate with Google Maps JavaScript API.
But, if you want to add dynamic locations from the database, it can be easily done with PHP and MySQL. You can add multiple markers with Info Window to Google Map dynamically from the database with PHP and MySQL.
For start development server, Go to the browser and hit below the url. In this codeigniter show/add markers and infowindows from database. We have successfully got the records from the database and show/add the markers with infowindows on google map php codeigniter.
The initMap () is a custom JavaScript function that initializes Google Maps. Define the Google Maps object and attach the map to the HTML element. Fetch the latitude, longitude, and marker icon image URL from the database and generate position array for multiple markers ( markers ).
I think you need to use "echo":
position: <?php echo $row['lat']?>, <?php echo $row['lng']?> ,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With