Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying markers on google map from mysql database using php/javascript

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!

like image 979
fst104 Avatar asked Aug 06 '15 12:08

fst104


People also ask

How to add custom markers to Google Maps using JavaScript?

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.

How to add dynamic locations in Google map using PHP?

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.

How to show/add markers with infowindows on Google map php codeigniter?

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.

How do I create a Google map in JavaScript?

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 ).


1 Answers

I think you need to use "echo":

position: <?php echo $row['lat']?>, <?php echo $row['lng']?> ,
like image 89
gusjap Avatar answered Oct 31 '22 05:10

gusjap