I'm using php and I want to fetch two columns from table like Latitude and Longitutde and add the markers on google map based on lat and long values, how i do..
Asked
Active
Viewed 105 times
1 Answers
-1
After you get latitude and longitude data,
<div id="map"></div>
<script>
function initMap() {
var myLatLng = {lat: <?php echo $lat; ?>, lng: <?php echo $lng; ?>};
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 4,
center: myLatLng
});
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
title: 'Hello World!'
});
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap">
</script>
API Key must be included

Оzgur
- 432
- 2
- 10
-
@Ozgur This is a rather javascript solution. – Bhavesh G Apr 08 '17 at 19:25
-
@BhaveshGangani Is there a way to add marker on google map, using only php? – Оzgur Apr 08 '17 at 19:33
-
Please include this in the answer about that. – Bhavesh G Apr 08 '17 at 19:33
-
@Ozgur sir Thanku, – Taranpreet Singh Apr 08 '17 at 19:38
-
@Ozgur sir, but there is another problem like i get 6 rows from table and using this code it fetch last row(6th) lat,lng value and add on map but, i want to add all 6 rows lat,lng value on map – Taranpreet Singh Apr 08 '17 at 19:45
-
@TaranpreetSingh multiple markers example here http://stackoverflow.com/questions/3059044/google-maps-js-api-v3-simple-multiple-marker-example – Оzgur Apr 08 '17 at 19:52