summaryrefslogtreecommitdiff
path: root/platform/android/src/geojson/position.cpp
blob: c0e6da38871a4a8f3e3b46af64426f10ede2e18e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include "position.hpp"

namespace mbgl {
namespace android {
namespace geojson {

mapbox::geojson::point Position::convert(jni::JNIEnv &env, jni::Object<Position> jPosition) {
    static auto method = Position::javaClass.GetMethod<jni::Array<jdouble> ()>(env, "getCoordinates");
    // Array with 0: longitude, 1: latitude (and optionally 2: altitude)
    auto coordinates = jPosition.Call(env, method);
    jdouble lngLat[2];
    coordinates.GetRegion(env, 0, lngLat);
    mapbox::geojson::point point(lngLat[0], lngLat[1]);
    jni::DeleteLocalRef(env, coordinates);
    return point;
}

void Position::registerNative(jni::JNIEnv &env) {
    // Lookup the class
    javaClass = *jni::Class<Position>::Find(env).NewGlobalRef(env).release();
}

jni::Class<Position> Position::javaClass;

} // namespace geojson
} // namespace android
} // namespace mbgl