Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Google Maps to search my own location data (Same functionality as Places search API, but for my own "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?

like image 977
Eran Medan Avatar asked Feb 03 '12 23:02

Eran Medan


1 Answers

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.

like image 164
miguev Avatar answered Sep 28 '22 02:09

miguev