使用 Google Places API 自定义 NearBuy Places

custom nearbuy places using google places api

本文关键字:Places NearBuy 自定义 API 使用 Google      更新时间:2023-09-26

我从互联网上得到这个。

// <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places">
var map;
var infowindow;
function initMap() {
  var pyrmont = {lat: -33.867, lng: 151.195};
  map = new google.maps.Map(document.getElementById('map'), {
    center: pyrmont,
    zoom: 15
  });
  infowindow = new google.maps.InfoWindow();
  var service = new google.maps.places.PlacesService(map);
  service.nearbySearch({
    location: pyrmont,
    radius: 500,
    type: ['store']
  }, callback);
}
function callback(results, status) {
  if (status === google.maps.places.PlacesServiceStatus.OK) {
    for (var i = 0; i < results.length; 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);
    infowindow.open(map, this);
  });
}  

如何在 5 英里半径内搜索自定义位置,例如 CVS 药房而不是商店?您能否提供有关附近搜索的全套属性的参考?

nearSearch() 方法访问 Google 服务器。因此,您无法添加数据。

另一种方法是融合表。如果您有自己的数据,请将其导入Google Fusion Table,并使用FusionTablesLayer实现您的数据。您可以使用 SQL 搜索数据。https://developers.google.com/fusiontables/docs/samples/nn_example