1

I am new to Android. In my application, customer is at a location. I want to find agents near-by to that customer using his/her latitude and longitude. How can I do this? customer is on one location & We want to search agents surronding that perticular customer.
I have latitude of customer and agents and based on I want to search agents(From customer's latitude longitude in surrounding area of 5 km. which agents are thare that i want to search).

Manisha
  • 109
  • 1
  • 12

2 Answers2

1

pseudocode

area = 100;
for a over allAgents
  if(Math.abs(a.x - customer.x) < area || Math.abs(a.y - customer.y) < area) 
    nearCustomerArray.add(a);
Michele
  • 6,126
  • 2
  • 41
  • 45
  • 1
    Note that this gives a rectangle of results. That may be sufficient approximation for a rectangular map, but might leave out some agents outside the square. – Piskvor left the building Sep 15 '11 at 13:53
  • Yeah good point, for a circlebased location window you need to do basically the same but with some arc math stuff ;) – Michele Sep 15 '11 at 13:57
0

If you already know agent's location, grab you current location using built-in device gps receiver.

Then, calculate distance between your coordinates and the one of the agent using distanceTo method of Location class

Finally, found the small distance among all the distances you calculated.

Community
  • 1
  • 1
Rainbowbreeze
  • 1,503
  • 1
  • 9
  • 14