如何使用 Google 地图搜索我自己的位置数据(与地点搜索 API 功能相同,但针对我自己的“地点”)

发布于 2025-01-02 12:20:48 字数 790 浏览 5 评论 0原文

请参阅相关问题:谷歌地图自定义本地搜索/搜索控件

我知道我可以在 Google 地图中创建自定义位置和信息窗口 例如 http://code.google.com/apis/ajax/playground/#info_windows_sharing_v3< /a>

据我所知,本地搜索可以找到附近的地点(公共场所)
例如 http://code.google.com/apis/ajax/playground/#localsearch_with_markers< /a>

但是我的问题很简单:如何将两者结合起来? 如何启用与本地/地点搜索功能相同的功能,但仅在自定义标记位置上启用(例如我自己的位置数据而不是 Google 的地点/本地数据)?

例如,如果我有一组自定义位置数据/标记(未发布到 Google Places),如何允许用户查找相对于地址或其当前位置的附近自定义地点的列表?

See related question: google maps custom local search / search control

I know I can create Custom Locations and Information Windows in a Google Map
e.g. http://code.google.com/apis/ajax/playground/#info_windows_sharing_v3

And I understand that Local Search can find near-by places (public ones)
e.g. http://code.google.com/apis/ajax/playground/#localsearch_with_markers

However my question is simple: how do I combine both?
How do I enable the same as the local/places search functionality but only on custom marker locations (e.g. my own location data rather than Google's places/local data)?

For example, if I have a set of custom location data/markers (not published to Google Places), how to allow the user to find a list of near by custom places relative to an address or his/her current location?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

叫嚣ゝ 2025-01-09 12:20:48

本地搜索 API 已弃用,因此您可能应该考虑迁移到地点 API

无论哪种情况,您所需要做的就是查询(搜索或)Places API,从结果中提取 LatLngs 并将标记放置在地图上。

我不确定您所说的自定义标记是什么意思,我猜要么 (a) 使用每个结果自己的图标作为标记的图标,要么 (b) 让用户在您的中搜索 数据(标记)而不是 Google 的本地/地点。

使用地点库可以轻松实现 (a)。在 place-search.html 示例中,您只需在 createMarker() 回调函数中添加一行:

function createMarker(place) {
  var placeLoc = place.geometry.location;
  var marker = new google.maps.Marker({
    map: map,
    icon: place.icon,
    position: place.geometry.location
  });

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

虽然原始图标看起来很大,所以您可能需要将它们缩小。

(b) 将是一个不同的故事,例如使用 PHP、MySQL 和amp; 创建商店定位器;谷歌地图

The Local Search API is deprecated, so you should probably look into moving to the Places API.

In either case, all you need to do is query the (Search or) Places API, extract LatLngs from the results and place your markers on the map.

I'm not sure what you mean with custom markers, I'd guess either (a) using each result's own icon as the marker's icon or (b) let users search among your data (markers) instead of Google's Local/Places.

(a) is kinda easy with the Places Library. In the place-search.html example you'd add just one line to the createMarker() callback function:

function createMarker(place) {
  var placeLoc = place.geometry.location;
  var marker = new google.maps.Marker({
    map: map,
    icon: place.icon,
    position: place.geometry.location
  });

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

Original icons looks big though, so you may want to scale them down.

(b) would be a different story, like Creating a Store Locator with PHP, MySQL & Google Maps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文