I have multiple longtitude and attitude data and I want to show them in the google map with pins.
How to use the google map API to do this?
You iterate over your array, and create a new Marker
instance for each pair. It's simple:
<script>
var map = new google.maps.Map(document.getElementById('map'), {
center: new google.maps.LatLng(55.378051, -3.435973),
mapTypeId: google.maps.MapTypeId.ROADMAP,
zoom: 8
});
var locations = [
new google.maps.LatLng(54.97784, -1.612916),
new google.maps.LatLng(55.378051, -3.435973])
// and additional coordinates, just add a new item
];
locations.forEach(function (location) {
var marker = new google.maps.Marker({
position: location,
map: map
});
});
</script>
This works for any number of latitude/longitude pairs; just add a new item to the locations
array.
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