0

I'm starting to create an application which will be show notification, when user will be within radius 1 km from my shop.

I have xml file, which show my shop lat and log:

<SHOPS>
<SHOP LON="19.456865000000000000" LAT="51.765639000000000000" CITY="90-423 Łódź" STR="ul. Piotrkowska 95" PHOTO=""/>
<SHOP LON="18.564883000000000000" LAT="54.443416000000000000" CITY="81-759 Sopot" STR="ul. Bohaterów Monte Casino 26" PHOTO=""/>
<SHOP LON="19.455248000000000000" LAT="51.770487000000000000" CITY="90-125 Łódź" STR="ul. Narutowicza 41" PHOTO=""/>
<SHOP LON="20.930370000000000000" LAT="52.241939000000000000" CITY="01-460 Warszawa" STR="ul. Górczewska 124" PHOTO=""/>
</SHOPS>

How can I do that, how to designate a radius of lat and long?

Dawid Sajdak
  • 3,064
  • 2
  • 23
  • 37

1 Answers1

0

If you want to find the distance between two diferent locations (i.e. the user location and one of your shps location) you can use the following code:

Location shopLoc = new Location("");    
shopLoc.setLatitude(shopLat); //get this value from your xml file
shopLoc.setLongitude(shopLon); //get this value from your xml file

Location userLoc = new Location("");
userLoc.setLatitude(userLat); //get this value from gps or other position device
userLoc.setLongitude(userLat); //get this value from gps or other position device

//Finaly get the distance with
float distance = userLoc.distanceTo(shopLocation)

Now you can compare the distance with 1 Km and show the notification

Luis
  • 11,978
  • 3
  • 27
  • 35