Google adds api to duplicate places

I am looking for places by keywords in the LatLngBounds array.

var boundsarr = new Array(); boundsarr[0] = new google.maps.LatLngBounds( new google.maps.LatLng(25.941886953491675, -80.17411103748543), new google.maps.LatLng(25.947676224813897, -80.16767330177947) ); boundsarr[1] = new google.maps.LatLngBounds( new google.maps.LatLng(25.941886953491675, -80.16767330177947), new google.maps.LatLng(25.94622890698334, -80.1644544339265) ); boundsarr[2] = new google.maps.LatLngBounds( new google.maps.LatLng(25.927413775186118, -80.1644544339265), new google.maps.LatLng(25.94622890698334, -80.15962613214703) ); boundsarr[3] = new google.maps.LatLngBounds( new google.maps.LatLng(25.927413775186118, -80.15962613214703), new google.maps.LatLng(25.931755728677782, -80.15801669822054) ); boundsarr[4] = new google.maps.LatLngBounds( new google.maps.LatLng(25.927413775186118, -80.15801669822054), new google.maps.LatLng(25.933203046508336, -80.15318839644107) ); boundsarr[5] = new google.maps.LatLngBounds( new google.maps.LatLng(25.92886109301667, -80.15318839644107), new google.maps.LatLng(25.933203046508336, -80.15157896251458) ); 

then adding markers to the map, into the array and creating a list of places returned using the marker array. Duplicate entries appear in the list, and I can’t understand why ..

Example: http://jsfiddle.net/2KrmY/ . How can I prevent duplicates from being displayed? Any help is much appreciated!

+6
source share
3 answers

As a workaround, could you put together an array of the found places in your callback every time, and then in the same loop, see if there is a counter> 1, and then do not call createMarker?

Not sure if perfect, but see below:

 var foundPlaces = []; var found; function callback(results, status) { if (status === google.maps.places.PlacesServiceStatus.OK) { for (var i = 0; i < results.length; i++) { found = 0; foundPlaces.push(results[i].id); for (var j = 0; j < foundPlaces.length; j++) { if (foundPlaces[j] === results[i].id) { found++; console.log(foundPlaces[j], results[i].id); } } if (found < 2) { createMarker(results[i]); } } } } 

http://jsfiddle.net/2KrmY/15/

+3
source

The bounds parameter is described below:

Ratings inside that will search for places. Both location and radius will be ignored if boundaries are specified.

But for the second ratings in your code example, 2 results fall outside the boundaries.

You can display the border area with:

 new google.maps.Rectangle({ strokeColor: 'red', strokeOpacity: 0.8, strokeWeight: 2, fillColor: 'bulue', fillOpacity: 0.6, map: map, bounds: bounds }); 

And then you can see the result.

Check out the demo .

It could be a google map error.

+3
source

You need to check before adding new borders, because when you click it again, it creates a new marker in the same place. use this ... map.getBounds().contains(marker.getPosition())

send old message

this will return true or false after checking this you can make / add a marker

I tried in the fiddle but still didn’t succeed ... like its JASON syntax .. and JavaScript require a specific function for the user data type. I am trying to create a custom function to eliminate a duplicate JSON object ....

I will keep you posted with the updated violin as soon as it is ready, until then you can try it yourself.

I hope this is done.

+1
source

Source: https://habr.com/ru/post/947332/


All Articles