简体   繁体   English

如何在Google Maps InfoWindow中为多个位置实现分页?

[英]How to implement pagination in a Google Maps InfoWindow for multiple locations?

I have google map with muliplte location and multiple marker in same location. 我有谷歌地图与muliplte位置和多个标记在同一位置。

My Map data will be like this 我的地图数据将是这样的

[{"DisplayText": "Test Window 1 - 1", "LatitudeLongitude": "61.095,10.547", "Location": "Oslo"},
{"DisplayText": "Test Window 1 - 2", "LatitudeLongitude": "61.095,10.547", "Location": "Oslo"},
{"DisplayText": "Test Window 2 - 1", "LatitudeLongitude": "61.585,8.369", "Location": "Ringebu Municipality"},
{"DisplayText": "Test Window 2 - 2", "LatitudeLongitude": "61.585,8.369", "Location": "Ringebu Municipality"},
{"DisplayText": "Test Window 1 - 3", "LatitudeLongitude": "61.095,10.547", "Location": "Oslo"},
{"DisplayText": "Test Window 3 - 1", "LatitudeLongitude": "61.778,11.3609", "Location": "Oslo Municipality"},
{"DisplayText": "Test Window 4 - 1", "LatitudeLongitude": "63.485,10.449", "Location": "Trondheim"}]

I need to display data which has same lat, long in a slider within Google infowindow. 我需要在Google infowindow的滑块中显示具有相同lat,long的数据。

There is a FIDDLE to display like that . 有一个FIDDLE可以这样显示。 But I need to display multiple markers with pagination features 但我需要显示具有分页功能的多个标记

This can be implemented manually, making use of the setContent method on the InfoWindow . 这可以手动实现,利用InfoWindow上的setContent方法。

I did a similar thing years ago - to see a demo of it in action, load the following page and wait a while for the markers to come up: http://www.auctionsearchkit.co.uk/search.php?satitle=test&site=UK . 几年前我做了类似的事情 - 看到它的实际演示,加载下面的页面并等待标记出现: http//www.auctionsearchkit.co.uk/search.php?sititle = test&site =英国 Then click on a few markers until you come to one where the infowindow has « < > » icons at the top (this is where more than one of the eBay search results is for the same seller). 然后点击几个标记,直到你到达一个信息窗口顶部有« < > »图标的地方(这是eBay搜索结果中不止一个是同一卖家的地方)。 You can check out the Javascript on the HTML page for more details but basically (with some bits cut out) you'll need something like this: 您可以在HTML页面上查看Javascript以获取更多详细信息,但基本上(有些位被删除)您需要这样的内容:

function getInfoWindowHtml(pc) {
  var infoWindowHtml = '<span' + MOUSE_OVER_HAND 
                               + ' title="View the first item at this location"'
                               + ' onclick="viewFirstItem(\'' + pc + '\')">'
                     + '&laquo;</span>&nbsp;'
                     + '<span' + MOUSE_OVER_HAND 
                               + ' title="View the previous item at this location"'
                               + ' onclick="viewPrevItem(\'' + pc + '\')">'
                     + '&lt;</span>&nbsp;'
                     + '<span' + MOUSE_OVER_HAND
                               + ' title="View the next item at this location"'
                               + ' onclick="viewNextItem(\'' + pc + '\')">'
                     + '&gt;</span>&nbsp;'
                     + '<span' + MOUSE_OVER_HAND
                               + ' title="View the last item at this location"'
                               + ' onclick="viewLastItem(\'' + pc + '\')">'
                     + '&raquo;</span>&nbsp;&nbsp;' :
                       '')
                   + '...etc...';
  }

  return infoWindowHtml;
}

...and code like the following to open it: ...和以下代码打开它:

  // Open the Info Window
  var html = getInfoWindowHtml(pc);
  infoWindow.setContent(html);
  infoWindow.open(map, marker);

You'll then need to implement viewFirstItem , viewLastItem , viewNextItem and viewPrevItem functions to change the infoWindow's HTML appropriately. 然后,您需要实现viewFirstItemviewLastItemviewNextItemviewPrevItem函数以适当地更改infoWindow的HTML。

To give you a full working answer would really take some time and experimentation, so these are the steps I would do: 为了给你一个完整的工作答案真的需要一些时间和实验,所以这些是我要做的步骤:

Find all the makers close to the one that has been clicked. 找到所有已被点击的制造商附近的制造商。 In your case they are at the same location, so maybe a radius of 10m would work. 在你的情况下,他们在同一个位置,所以也许半径为10米的工作。 Finding all the markers inside a given radius 查找给定半径内的所有标记

Create an variable to contain the infoWindow content and add to it for each maker that falls within that location. 创建一个变量以包含infoWindow内容,并为属于该位置的每个制造商添加该内容。 Then display that location. 然后显示该位置。

The other solution that could work would be to combine all of the infoWindow content you want for a set of markers in the first place, and then just add one maker to represent that group of markers. 另一个可行的解决方案是首先将所需的所有infoWindow内容组合成一组标记,然后添加一个制造商来表示该组标记。 In some way adding multiple makers to the same location is counter intuitive, as only one will ever be clicked. 在某种程度上,将多个制造商添加到同一位置是违反直觉的,因为只会点击一个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM