JNIEXPORT void JNICALL Java_com_uber_h3core_NativeMethods_cellToLatLng()

in src/main/c/h3-java/src/jniapi.c [272:298]


JNIEXPORT void JNICALL Java_com_uber_h3core_NativeMethods_cellToLatLng(
    JNIEnv *env, jobject thiz, jlong h3, jdoubleArray verts) {
    LatLng coord;
    H3Error err = cellToLatLng(h3, &coord);
    if (err) {
        ThrowH3Exception(env, err);
        return;
    }

    jsize sz = (**env).GetArrayLength(env, verts);
    jdouble *coordsElements = (**env).GetDoubleArrayElements(env, verts, 0);

    if (coordsElements != NULL) {
        // if sz is too small, we will fail to write all the elements
        if (sz >= 2) {
            coordsElements[0] = coord.lat;
            coordsElements[1] = coord.lng;
        }

        // 0 is the mode
        // reference
        // https://developer.android.com/training/articles/perf-jni.html
        (**env).ReleaseDoubleArrayElements(env, verts, coordsElements, 0);
    } else {
        ThrowOutOfMemoryError(env);
    }
}