Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How auto open infoWindow in gmaps v0.3

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.

like image 494
daiguachen Avatar asked Feb 27 '13 08:02

daiguachen


People also ask

How do I put infowindow on marker?

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.

How do I open multiple Infowindows in Google Maps?

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.

How do you change the infowindow position on Google Maps?

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.


1 Answers

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

like image 179
Tommy Bjerregaard Avatar answered Oct 06 '22 01:10

Tommy Bjerregaard