0

We want to draw an arrow from current location to destination position, using only geolocator to constantly update location.

Using this method we can calculate the distance between two points, but how can we use that to reach the idea of arrow on the screen?

Is there an approach derived from latitude and longitude nature as they are basically degrees/minutes/seconds?

I am looking for the idea used in applications like GPS Arrow Navigator, for example. i.e. the way you can navigate to a position and keep updating the arrow even if you go for the wrong direction

TiyebM
  • 2,684
  • 3
  • 40
  • 66

3 Answers3

1

You could use flutter_mapbox_navigation package. enter image description here

Or if you'r trying to calculate the bearing between two geocoordinates you can use the bearingBetween method. The bearingBetween method also takes four parameters:

  1. startLatitude: Latitude of the start position

  2. startLongitude: Longitude of the start position

  3. endLatitude: Latitude of the destination position

  4. endLongitude: Longitude of the destination position

    import 'package:geolocator/geolocator.dart';
    
    double bearing = Geolocator.bearingBetween(52.2165157, 6.9437819, 52.3546274, 4.8285838);
    
Cristian Cruz
  • 479
  • 5
  • 6
1

I think, you know while creating instance of Position object in "geolocator" package , you can specify heading parameter of it. There is already ready method to calculate it:

https://pub.dev/documentation/geolocator/latest/geolocator/Geolocator/bearingBetween.html

It is scientific explanation of how heading is calculated:

Let ‘R’ be the radius of Earth,

‘L’ be the longitude,

‘θ’ be latitude,

‘β‘ be Bearing.

Denote point A and B as two different points, where ‘La’ is point A longitude and ‘θa’ is point A latitude, similarly assume for point B. Bearing would be measured from North direction i.e 0° bearing means North, 90° bearing is East, 180° bearing is measured to be South, and 270° to be West.

Formula to find Bearing, when two different points latitude, longitude is given: Bearing from point A to B, can be calculated as,

β = atan2(X,Y),

where, X and Y are two quantities and can be calculated as:

X = cos θb * sin ∆L

Y = cos θa * sin θb – sin θa * cos θb * cos ∆L

Lets us take an example to calculate bearing between the two different points with the formula:

Kansas City: 39.099912, -94.581213 St Louis: 38.627089, -90.200203 So X and Y can be calculated as,

X = cos(38.627089) * sin(4.38101)

X = 0.05967668696

And

Y = cos(39.099912) * sin(38.627089) – sin(39.099912) * cos(38.627089) * cos(4.38101)

Y = 0.77604737571 * 0.62424902378 – 0.6306746155 * 0.78122541965 * 0.99707812506

Y = -0.00681261948

Convert θ into radians

So as, β = atan2(X,Y) = atan2(0.05967668696, -0.00681261948) = 1.684463062558 radians

This means, from Kansas City if we move in 96.51° bearing direction, we will reach St Louis.

Jakhongir Anasov
  • 1,207
  • 7
  • 16
0

if you want to use a map other than google maps, you can use the integrated flutter map.

Arel DY
  • 1
  • 1
  • Thank you, but the question is about showing arrow during navigation from current position to destination position. – TiyebM Oct 03 '22 at 23:32
  • Can you provide some link or example? Your answer simply doesn't answer anything! – Christian Dec 29 '22 at 18:28