2

Suppose we have two beacons placed in both sides of the road. We know their latitude and longitude where they are positioned (we treat them as a location). We also know the distance in meters between these two beacons (measered using Haversine Formula). Our device is moving between(inside range of these beacons) these two points.Is there out any function that will help us calculate our current position based on the distance between two beacons or based on the distance from device to a single beacon? How can i find the location of the device based on these data i have, or is there any thing that will be useful to achieve what i want?

SHORTLY: I want to know where the user is located between two BEACONS without using GPS System but the data i have from the beacon (in this case: Exact Beacons locations, exact distance from user to the beacon and the exact distance between two beacons)

As an illustration: (Filled Black dots are BEACONS with an imaginary Range, Red dots are some user unknown positions and Green Lines are the Known Distances ; we also know the latitude and longitude of Black Dots) Based on these data i want to find the position of user (Single Red Dot)

enter image description here

note: I checked out this question however i didnt understand why the location is returned as an int and why time t is included there.

Community
  • 1
  • 1
hrskrs
  • 4,447
  • 5
  • 38
  • 52
  • Suppose we have both lat and long.. you want know were the mobile is between these point ? – Jamil Dec 26 '14 at 13:06
  • yeah(Lat and long of two positioned beacons i mean), but Using the data i have (beacon distances, Distance between beacons and Two Points locations). – hrskrs Dec 26 '14 at 13:12
  • let me show you in answer what you are saying in this question.please check my answer. – Jamil Dec 26 '14 at 13:22

2 Answers2

0

Here the Methods to set the locations and get the distance from where you are standing between these two point.

 private Location BeaconLocation1() {

        Location location = new Location("POINT_LOCATION1");
        location.setLatitude(45.0);
        location.setLongitude(45.0);
        return location;
    }

  private Location BeaconLocation2() {

        Location location = new Location("POINT_LOCATION2");
        location.setLatitude(45.5);
        location.setLongitude(45.5);
        return location;
    }

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

            Location pointLocation1 = BeaconLocation1();
            Location pointLocation2 = BeaconLocation2();

            float distance1 = location.distanceTo(pointLocation1);
            float distance2 = location.distanceTo(pointLocation2);

            Toast.makeText(MapsActivity.this,
                     "Distance from Point1: "+distance1+" Meters", Toast.LENGTH_LONG).show();
          Toast.makeText(MapsActivity.this,
                     "Distance from Point2: "+distance2+" Meters", Toast.LENGTH_LONG).show();
        }
    public void onStatusChanged(String s, int i, Bundle b) {
        }
    public void onProviderDisabled(String s) {
        }
    public void onProviderEnabled(String s) {
        }
}

EDIT :

see this post

convert meters to latitude longitude from any point

Community
  • 1
  • 1
Jamil
  • 5,457
  • 4
  • 26
  • 29
  • this is for finding distance between your device and beacon as i understood. The thing i want is to find `Point3` by using these data. For clearity: We have Point1 and Point2 exact location and distance between them or till them. THere exist Point3 which moves inside these two Points range. How can i find Latitude and Longitude of this 3d Point – hrskrs Dec 26 '14 at 13:36
  • ok so you want to know the lat long of POINT3 on the basis of these distances? – Jamil Dec 26 '14 at 13:41
  • you dont know the lat long of the POINT3? in my case the Lat Long of Point3 is the mobile and Point1 and point2 are fixed. – Jamil Dec 26 '14 at 13:44
  • yeah exactly. As i am using beacons i want to get the exact position of the device every x seconds. `onLocationChanged` is based on the GPS position. Shortly i want to get the position using beacon data so later on i can show which path the device should follow. GPS is not that much accurate for such things. – hrskrs Dec 26 '14 at 13:48
  • http://stackoverflow.com/questions/19077215/how-to-convert-polar-system-to-latitude-and-longitude – Jamil Dec 26 '14 at 16:06
  • in some cases yes it is not accurate but if you implement it in way like forcefully getting the lat long at every interval of time then you can make it accurate as every second the lat long will be forcefully updated. – Jamil Dec 26 '14 at 16:09
  • According to my opinion you could use GPS system to achieve what you want in this scenario. – Jamil Dec 26 '14 at 18:38
0

To focus on your question, no there is no one-shot formula to do everything but there are some to make the process easier. You will have to look around in a whole bunch of math libraries to find them though.

This is the theory behind it.

Okay so we require the latitude and longitude of point 3. I'm going to explain the theory behind it as the code is just too much for me to do right now.

For this we will make use of the bearing from one point to another. You can use this link to get that formula: Bearing formula

I am assuming we know the distance between the device and each of the separate beacons otherwise this is impossible unless you want to use a sort of radar approach to identify this. I can't really help with that. If we do know this we can construct imaginary circles around the two beacons using the distance from them to the device as their radii.

E.g. From device to beacon one is 500 meters. From device to beacon 2 is 200M. Draw an imaginary circle around beacon one with a raduis of 500M and a imaginary circle around beacon two with a radius of 200M.

obviously we can't construct these circles programatically it would be too tedious. So we will use the equation of a circle: (x -h)^2 + (y - k)^2 =r^2.

Quick high school revision reveals that h and k are the x and y coordinates of the center of the circle, an offset from the Cartesian plain. we will center our imaginary Cartesian plain at point one. Now we will workout the bearing to point two an use the distance from point to to construct a line from 0,0 on our Cartesian plane(Point 1) to point 2. Using tan of our bearing we get the gradient of the line. Now we will use cos and sine of our bearing and using the distance of our hypotenuse to obtain the y and x position of beacon 2 relative to beacon 1 on our Cartesian plane. Now we will sub these values back into our circle equations:

your first equation will always be: (x -0)^2 + (y - 0)^2 =r^2. Where r is the radius in this example 500M. second equation is (x -h)^2 + (y - k)^2 =r^2.Where r is the radius in this example 200M. Except now h will be your calculated x value above and y will be the calculated y value above.

Now for the tricky party. We need to find where these circle intersect. From our buddies at math stack exchange i got the formula.Points of intersection

Now your circles might have zero 1 or two point of intersection based on the devices position. If you get two results you will have to run the entire thing again while the device is moving to see whether we are moving closer or further away from the centers of the circles. From that we can conclude which side is the correct point and the we can dram a straight line to beacon 1 on our Cartesian plain, obtain the gradient of the line, convert it into a bearing from beacon 1 and then reverse engineer the haversine and bearing formula to get the co-ordinates.

It's not pretty or easy but you'll get there eventually. This is most likely not the only solution so feel free to go searching for other ones. Best of luck.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
TheUnkown
  • 33
  • 1
  • 10
  • That edit is not correct representation of what I meant. I am not allowed to comment on your question. Try to read through what i just said. The imaginary circle have nothing to do with the range of the beacons. – TheUnkown Dec 26 '14 at 18:16
  • I think this [question](http://stackoverflow.com/questions/10119479/calculating-lat-and-long-from-bearing-and-distance) is similar to what you are saying. The only thing here is that i have to calculate `distance` and `bearing` and give them as parameters to that function. i calculated `distance` with `Haversine`. WHat about the `bearing`? – hrskrs Dec 29 '14 at 09:01