This is the first time I am doing something on google map2. I have stored the lat and lang to my database and I want to display all of that on my map. Now I would like to get the marker on each pin. Here is my code for it:
<script type="text/javascript">
function GMaps_Load()
{
if (GBrowserIsCompatible())
{
var map = new GMap2(document.getElementById("GMaps_canvas"));
map.addControl(new GSmallMapControl());
map.addControl(new GSmallMapControl());
<?php if(count($val) >0){ ?>
var cords = [23.32323,32.43455
22.5656,27.656464]
for ( var i = 0; i < cords.length; i++ )
{
var marker = new GMarker( cords[ i ] );
//alert(cords[ i ]);
map.addOverlay( marker );
}
// #2a -- calculate center
var latlngbounds = new GLatLngBounds( );
for ( var i = 0; i < cords.length; i++ )
{
latlngbounds.extend( cords[ i ] );
}
// #2b -- set center using the calculated values
map.setCenter( latlngbounds.getCenter( ), map.getBoundsZoomLevel( latlngbounds ) );
//22.9946923,72.5282428
map.openInfoWindow(map.getCenter(),document.createTextNode("Hello, world"));
map.addOverlay(marker); }}
</script>
here you can see in this line of code map.openInfoWindow(map.getCenter(),document.createTextNode("Hello, world"));
I get the popup in the centre of the map but I would like it on all the pins. How can I achieve that?
Thanks in advance
Unless I'm reading your code wrong you're only passing 1 parameter to the marker, cords[I] would contain 1 number entry from the array instead of a valid LatLng set of values as required.
Check the API for details on how to create a LatLng.
Official documentation says that Version 2 of this API has been officially deprecated. Please use version 3.
Adding infowindows to markers is simple. See this example .
With gmaps.js it gets more simpler :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.