How to use Google Maps to search my own location data (Same functionality as Places search API, but for my own “places”)

非 Y 不嫁゛ 提交于 2019-12-02 17:44:06

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!