0

I have a list of store addresses, and I'm trying to create a map out of it. Using the Places API I am able to retrieve most of the informations and manually create and place the markers on the map:

const service = new google.maps.places.PlacesService(map);
service.findPlaceFromQuery({
  query: '212 Enterprise Dr, Rockaway, Frank Pizza',
  fields: ['all']
}, onPlaceFound);

However I'd like to select the original marker instead of overlapping a new one.

That is because I want the user to be able to open the default info window with store phone number, directions and stuff.

I know that I can re-create it, but it feels kinda lame since all the info is already there.

Original GM Marker Custom Marker

This SO post ask about the same, yet no solution has been found.

AlexanderD
  • 596
  • 2
  • 10
  • 22

1 Answers1

-2

Based on the documentation found here, which shows findPlaceFromQuery(), the second parameter of findPlaceFromQuery should be a function where the first argument of that function is an Array of placeResults.

Therefore, after reviewing a link here and here your onPlaceFound function should be looking something like:

function onPlaceFound(placeResultsArray){
  const firstResult = placeResultsArray[0], firstIconURL = firstResult.icon;
  const latLng = firstResult.geometry.location, lat = latLng.lat(), lng = latLng.lng();
  // do stuff with those variables here
}
  

Of course, that does not select Google's result as a Marker, but now you have the actual icon, and latitude and longitude.

StackSlave
  • 10,613
  • 2
  • 18
  • 35
  • 1
    I know, and that's what I am able to do right now. But what i want to do is to filter out the places and leave only / select the ones at the coordinates I get, and not to place a new marker – AlexanderD Sep 20 '21 at 14:25
  • 1
    Well, there you have it. Nobody has an answer to your problem. Google sucks. – StackSlave Sep 21 '21 at 00:01