Locations

Former Member
Former Member
A couple of questions regarding location:

What is the type of latitude and longitude elements in location.getRadians()?
info.currentLocation.toRadians()[0]
gets me an object. If I do .toDouble() I still get an object. With .toNumber() is lose all precision and .toString().toFloat() seems overkill.

What's best practice for calculating distances between 2 locations?
I'm using the Great Circle formula at the moment.
Will there be helper methods in ConnectIQ (like Location.distanceTo(other))?
  • All primitive types in MonkeyC are objects, so it isn't a surprise that you are getting an object. I'm not at my dev box right now, but I'm fairly certain that the return type type is Double. You can use the instanceof operator to tell you...

    if (info.currentLocation[0] instanceof Lang.Double) {
    Sys.println("It is a double");
    }


    I think the Great Circle or the Haversine formula would work fine. I'd probably use Haversine, but it is up to you.
  • Former Member
    Former Member over 10 years ago
    Yes, that's what I would have expected. Double checked and.... it's a Double.
    Looks like there's a bug in implicit string conversion (as in concatenation) with a Double.
    Feel kinda stupid now :o.
    Thank you.
  • Yeah, the bug exists for Long and Double. The ConnectIQ team already knows about it.
  • Also note that for less than 100 km (approx 60 mi) you can even use pythagorean theorem as the difference is going to be very small.