I have a problem about gmaps v0.3 that when I addMarker How let infoWindow auto open. not when you onclick open.
<script type="text/javascript">
var map;
$(document).ready(function(){
map = new GMaps({
div: '#map',
lat: 39.908403,
lng: 116.397529,
zoom: 1,
});
var marker = new google.maps.Marker();
marker = {
lat: 39.908403,
lng: 116.397529,
title: 'Lima',
//map: map.map,
//animation: google.maps.Animation.BOUNCE,
//shape: {coords: [0,0,50,50], type: "rect"},
infoWindow: {
content: '<font color="red">hello world</font>'
}
}
map.addMarker(marker);
});
I want to when addMarker auto open infoWindow not click, what should I do. please help me.
Move an info windowAttach the info window to a new marker using the InfoWindow. open() method. Note: If you call open() without passing a marker, the InfoWindow will use the position specified upon construction through the InfoWindowOptions object literal.
By assigning the infowindow to a marker property, each marker can have it's own infowindow. This was how I approached the problem, with the relevant sample code. //create a marker object first, or instantiate it by passing a JSON to the constructor. //this can be done inside a for loop var infowindow = new google.
An InfoWindow can be placed on a map at a particular position or above a marker, depending on what is specified in the options. Unless auto-pan is disabled, an InfoWindow will pan the map to make itself visible when it is opened. After constructing an InfoWindow, you must call open to display it on the map.
You can open the infoWindow by using the .open
function:
// Create map
var map = new GMaps({
div: '#map',
lat: 39.908403,
lng: 116.397529,
zoom: 1,
});
// Create infoWindow
var infoWindow = new google.maps.InfoWindow({
content: 'Content goes here..'
});
// Create marker
var marker = new google.maps.Marker({
lat: lat,
lng: lng,
title: 'Lima',
map: map.map,
infoWindow: infoWindow
});
// This opens the infoWindow
infoWindow.open(map, marker);
You can read about infoWindow at the Google Maps website https://developers.google.com/maps/documentation/javascript/overlays#InfoWindows
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