0
votes

I am trying to replicate a gps reminder app. Currently the user will able to choose a point through a map and set it as a location. and then add a range to it.

when the user comes to that range the alarm has to ring.

my current obstacle is to add a range lets say 1KM to the latitude and longitude point set by the user and get a new latitude longitude point.

Is there any other method through which I could match the users current location with the range?

I tried the formula below. but I am not getting the desired results.

  • CalcLatitude: 1 deg = 110.54 km
  • CalcLongitude: 1 deg = 111.320*cos(latitude after adding km)
  • NEW Latitude = Old Latitude + CalcLatitude
  • OLD Longitude = Old Longitude + CalcLongitude
2
have you checked proximity alert in android. Here you can set the target lat/log along with radius. Please check javacodegeeks.com/2011/01/…NullPointerException

2 Answers

0
votes
private class MyLocationListener implements LocationListener {
    public void onLocationChanged(Location location) {

            Location alarmLocation = new Location("Alarm");

            alarmLocation.setLatitude(Double.valueOf(alarm_loc_latitude)); //here alarm_loc_latitude is the value of latitude of the location where alarm is going to ring 
            alarmLocation.setLongitude(Double.valueOf(alarm_loc_longitude)); // Same for alarm_loc_longitude

            double distance = location.distanceTo(alarmLocation); // it will calculate the distance between your current location and the alarm location, in metres


            if(distance<=1000){  // distance in metres

                    /* Enter your alarm ringing code here */ 


            }

         }

    }     

Use this location listener in your activity. This will continuously check your current location in certain time intervals, and calculate its distance from your alarmlocation each time. When the distance will be less than 1000 metres, your alarm will ring.

0
votes

The simplest approach is to define the range as circle whith center point (lat, lon) and radius in meter.

You warn when the user location is inside the circle.
A point is inside a circle if the distance from current location to center is less than the radius (1000m) in your case.

Simply use the currentlLocation.distanceTo() method to calculate the distance from current location to center of warning circle.