Closed gelinger777 closed 1 year ago
Hi, did you finally found a flutter plugin that handles geo AR ? Thanks
@jeromeDms unfortunately no. The only one was there was from wikitude , but after they were aquired by qualcom they struggle to release new version for newest flutter since november ! And this is when its a commercial product which costs 2k yearly ! Thats very sad
@CariusLars could you maybe find time and help us in a right direction?
Hi. If I understand you correctly, you need to position the object with the geo-position relative to the user in AR. Here is my solution to calculate position vector for ARNode:
/// Returns position vector for node
///
/// Mark: [heading] is phone angel to True North in degrees
Vector3 positionVector(Position userPosition, double heading, LatLng nodeLocation) {
final location1 = LatLng(userPosition.latitude, userPosition.longitude);
final double bearing = MapUtil.sphereAngel(location1, nodeLocation);
final double distance = MapUtil.sphereDistance(location1, nodeLocation);
final double x = distance * cos(bearing);
final double z = -distance * sin(bearing);
final vector = Vector3(x, -1, z);
vector.applyAxisAngle(Vector3(0, 1, 0), radians(heading));
return vector;
}
double radians(double degrees) => degrees * pi / 180;
class MapUtil {
/// Earth radius in meters
static const double earthRadius = 6372795;
/// Returns the angle from [location1] to [location2] in radians
static double sphereAngel(LatLng location1, LatLng location2) {
final double lat1 = radians(location1.latitude);
final double lon1 = radians(location1.longitude);
final double lat2 = radians(location2.latitude);
final double lon2 = radians(location2.longitude);
final delta = lon2 - lon1;
final x = cos(lat2) * sin(delta);
final y = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(delta);
return atan2(x, y);
}
/// Returns distance between [location1] and [location2] on earth sphere in meters
static double sphereDistance(LatLng location1, LatLng location2) {
// radians
final double lat1 = radians(location1.latitude);
final double lon1 = radians(location1.longitude);
final double lat2 = radians(location2.latitude);
final double lon2 = radians(location2.longitude);
// cosines and sines of widths and longitude difference
final double cl1 = cos(lat1);
final double cl2 = cos(lat2);
final double sl1 = sin(lat1);
final double sl2 = sin(lat2);
final double delta = lon2 - lon1;
final double cdelta = cos(delta);
final double sdelta = sin(delta);
// calculating the length of a great circle
final double y =
sqrt(pow(cl2 * sdelta, 2) + pow(cl1 * sl2 - sl1 * cl2 * cdelta, 2));
final double x = sl1 * sl2 + cl1 * cl2 * cdelta;
final double ad = atan2(y, x);
return ad * earthRadius;
}
}
And then use it like this:
ARNode(
...
position: positionVector(position, heading, object),
...
)
Sadly this example doesn't produce any consistent results on my Nothing Phone (1). Can someone share their experience with this implementation or is there a different approach I could try?
It seems there is a branch called 'gps-objects', but last commit has about 2 years, and it seems not fully implemented. Still looking for a flutter solution to achieve geo-based POIs to AR. Did you progress on this issue ? Thanks
I am tired to search.. I think I will have to go with commercial one.I am not naming it not to seems promoting them.
@gelinger777 Please do share the name of the commercial product that you're using. I'm looking to do the same thing, where I want to plot for sale / for lease sign images in front of listed properties around the user, which requires anchoring the images to the lat/long coordinates of the properties.
Hi Everybody. I struggle to find a good replacement for https://github.com/kitcarson88/ionic-augmented-reality so that we could migrate our app from ionic to flutter. Do you have maybe an example of how to detect if in front of you is a GEO POI and show a pin properly on screen?