如何使用Google地图搜索我自己的位置数据(与Places搜索API功能相同,但适用于我自己的“地点”) [英] How to use Google Maps to search my own location data (Same functionality as Places search API, but for my own "places")

查看:115
本文介绍了如何使用Google地图搜索我自己的位置数据(与Places搜索API功能相同,但适用于我自己的“地点”)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我知道我可以在Google Map
中创建自定义位置和信息窗口。 http://code.google.com/apis/ajax/playground/#info_windows_sharing_v3



据我所知,本地搜索可以找到附近的地方(公共区域)

eg http://code.google.com/apis/ajax/playground/#localsearch_with_markers



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



例如,如果我有一组自定义位置数据/标记(未发布到Google地方信息),那么如何让用户找到相对于地址或他/她当前位置的自定义地点列表? rel =noreferrer>本地搜索API 已被弃用,因此您应该考虑转向 Places API



无论哪种情况,您只需查询(Search或)Places API,将LatLngs从结果中获得,并将您的标记放置在地图上。



我不确定您对自定义标记的含义,我猜(一个) 使用每个结果自己的图标作为标记的图标,或者(b)让用户在您的数据(标记)之间进行搜索,而不是Google的Local / Places。



(a)对于 Places库很容易。在 place-search.html 示例中,您'd只添加一行到 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>

(b)将会是不同的故事,例如使用PHP,MySQL和Excel创建商店定位器Google地图


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?

解决方案

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.

这篇关于如何使用Google地图搜索我自己的位置数据(与Places搜索API功能相同,但适用于我自己的“地点”)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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