Google Maps - Getting the info window to show?

最后都变了- 提交于 2019-12-22 18:01:46

问题


I've currently got a Google Map showing successfully and it looks like this:

I want it to show with the info window showing by default, like this example:

I read this page: http://code.google.com/apis/maps/documentation/javascript/overlays.html#InfoWindows but that seemed to only explain how to make an info window with your own custom content. I just want to show the info like the example above where you see on many sites.


回答1:


You can use the Places API:

http://code.google.com/apis/maps/documentation/places/

Or the Places Library (part of the Google Maps JS API):

http://code.google.com/apis/maps/documentation/javascript/places.html

You'll parse the response in JS and then set the content of the infowindow as needed. Note that scraping content from business listings (at least on Google's domains) to fill your infowindows is against the terms of service.

Here is a basic example:

http://code.google.com/apis/maps/documentation/javascript/examples/place-details.html




回答2:


This is how I've done it on map on my site (opens this type of the popup by default): in the initialization function I wrote

map.openInfoWindow(new GLatLng(coordinates), 'html code for the text in window');
var baseIcon = new GIcon(G_DEFAULT_ICON);
baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
baseIcon.iconSize = new GSize(20, 34);
baseIcon.shadowSize = new GSize(37, 34);
baseIcon.iconAnchor = new GPoint(9, 34);
baseIcon.infoWindowAnchor = new GPoint(9, 2);

But this one is only for the map on your website. For the general data in Google, available to everyone, it is not so simple, of course ) For your business to appear on the map you have to go here http://www.google.com/local/add/businessCenter or read this link http://support.google.com/adwords/bin/answer.py?hl=en&answer=143287



来源:https://stackoverflow.com/questions/8992890/google-maps-getting-the-info-window-to-show

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!