0

in my maps app i have to find the places (bank,ATM,cafe,bar..) inside bound of selected locations.Actually i have to get the places which are centre to the given locations.

for example i have 4 places a,b,c,d i have to get all banks inside bounds of these 4 places and have show them on map.

i can get nearest places for each location individually by using GooglePlaces API.but i need show places which are centre(approximately) to these 4 places.

please give me any suggestions how to do this or any example code or any other tutorials or links....

Thanks

Raki.

enter image description here

Ravi
  • 2,441
  • 1
  • 11
  • 30

2 Answers2

1

Your solution would be to take the average lat/lon of your points and then hit your Google API to get locations in that area. This average will be in the middle of however many coordinates you have. Example:

double totalLat = 0;
double totalLon = 0;

for(CLLocationCoordinate2D coordinate in coordinateArray)
{
    totalLat += coordinate.latitude;
    totalLon += coordinate.longitude;
}

// Use this average coordinate (which is the center of your points) to hit your Google API
CLLocationCoordinate2D averageCoordinate = CLLocationCoordinate2DMake(totalLat / coordinateArray.count, totalLon / coordinateArray.count);

Note: I haven't actually tested this, so don't just copy/paste, but it's the general idea.

Stonz2
  • 6,306
  • 4
  • 44
  • 64
  • @raki if the solution worked for you, consider marking this as the accepted answer so that it clears from unanswered question lists. – Stonz2 Feb 27 '15 at 18:56
0

You can always use the radius parameter defined in the Places API to get this information.

Please follow this Stack Overflow answer for more details.

Community
  • 1
  • 1
AniV
  • 3,997
  • 1
  • 12
  • 17
  • if there is lot of locations it is difficult to call search api with radius for every locations and finding the nearest place to all those locations....right ? – Ravi Feb 20 '15 at 05:50