Google Maps Places API,如何从标记中获取标准信息窗口内容 [英] Google Maps Places api, how do I get the standard infowindow content from a marker

查看:76
本文介绍了Google Maps Places API,如何从标记中获取标准信息窗口内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是Google地图的新手,也不是脚本专家.预先感谢您提供的任何帮助.

New to Google Maps, and not a script expert either. Thanks in advance for any help you can provide.

我正在将Google地图放在商店位置页面上.我已经设法通过搜索使地图显示想要的商店位置标记.现在,我希望填充infoWindow以使其看起来像标准的google窗口.但是使用我能够在地方图书馆中找到的代码,结果显示为无格式,没有换行符,如果缺少信息则显示错误,等等. -如果您已经回答了这个问题,请原谅我-我已经多次阅读过Google地方信息库,因此我很专心或者他们只是不解决这个特定问题.

I am putting a google map on a page of store locations. I have managed to get the map to display the marker I want for the store location using the search. Now I want the infoWindow to be populated to look like the standard google window. But using the code I was able to find on the places library, the results show up unformatted with no line breaks, and shows errors if a piece if information is missing, etc... I have searched and didn't find anything that helped - so please forgive me if this is already answered - and I have read through the google places library numerous times so either I am dense or they just don't address this specific question.

用户将单击页面上列出的商店位置,我想用一个标记向他们显示地图(通过搜索,我想我可以实现),并且我希望商店信息显示在infoWindow中当他们单击标记时(最好我希望infoWindow已经打开,但是我也找不到任何东西).由于我是该站点的新手,所以我无法发布infoWindow的图像,因此希望它不需要.像Google的地图网站一样,我想要一个格式正确的名称,声誉星号,格式正确的地址,电话号码和网站,以及商家的图片(如果有).我在下面使用的示例适用于所有此类信息都存在于google中的企业.包括我目前用于地图的代码.

The user will click on a store location listed on the page and I want to show them the map with the one marker (through search I think I can get that to happen) and I want the store information show up in the infoWindow when they click on the marker (preferably I would like the infoWindow already opened but I couldn't find anything on that either). Since I am new to the site I can't post an image of the infoWindow so hopefully it's not needed. Like the google's map website, I want a nicely formatted name, the reputation stars, a formatted address, phone number and website, along with a picture of the business if it exists. The example I use below is for a business where all of this information exists within google. The code I currently have for the map is included.

请不要仅仅为了将我带回到地方图书馆而回覆;如果仅此而已,那就无济于事.我需要澄清一下,理想情况下是一个例子.谢谢.

Please don't reply simply to direct me back to the places library; if that's all you have then it is not helping. I need some clarification and ideally an example. Thanks.

 <script type="text/javascript">
    var map;
    var service;
    var infowindow;

    function initialize() {
    var mvale = new google.maps.LatLng(40.708572,-74.017385);

    map = new google.maps.Map(document.getElementById('map_canvas'), {
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      center: mvale,
      zoom: 16
    });

    var request = {
      location: mvale,
      radius: '500',
    keyword: "Michelle Vale"
    };

    infowindow = new google.maps.InfoWindow();
    var service = new google.maps.places.PlacesService(map);
     service.search(request, callback);
    }

    function callback(results, status) {
    if (status == google.maps.places.PlacesServiceStatus.OK) {
       for (var i = 0; i < results.length; i++) {
         var place = results[i];
         createMarker(results[i]);
    }
    }
    }
    function createMarker(place) {
        var placeLoc = place.geometry.location;
        var marker = new google.maps.Marker({
          map: map,
          position: place.geometry.location
        });

        google.maps.event.addListener(marker, 'click', function() {
          infowindow.setContent(place.name + place.rating + place.vicinity + 
          place.formatted_address + place.website );
          infowindow.open(map, this);
        });
      }

    function openInfoWindow(id){return true;}

    google.maps.event.addDomListener(window, 'load', initialize);
    </script>

推荐答案

我终于在另一个这是我的示例:

 infowindow.setContent('<span style="padding: 0px; text-align:left" align="left"><h5>' + place.name + '&nbsp; &nbsp; ' + place.rating 
                            + '</h5><p>' + place.formatted_address + '<br />' + place.formatted_phone_number + '<br />' +  
                            '<a  target="_blank" href=' + place.website + '>' + place.website + '</a></p>' ) ;

我还弄清楚了如何使用地方信息库中描述的getDetails函数

I also figured out how to use the getDetails function described in the Places Library

我还是不知道如何获取评分信息(我正在使用标记,但它给出了错误),如何检索该位置的图像或如何消除出现未定义"错误.

I still don't know how to get the rating information (I'm using the tag but it gives an error), how to retrieve the image for the location, nor how to eliminate the "undefined" error from appearing.

最后一个元素是要在地图加载时打开 infoWindow ....

Last element is to have the infoWindow open when the map loads... I saw a post about it but couldn't get it to work.

这篇关于Google Maps Places API,如何从标记中获取标准信息窗口内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆