static jboolean getLocation(jobject locationInfo, jobject string_obj, ProviderInfo *pInfo) { jint i; jfieldID fid; jboolean ret = KNI_FALSE; if(pInfo != NULL) { if (pInfo->lastLocationTimestamp != 0) { /* Get location parameters */ KNI_SetBooleanField(locationInfo, locationInfoFieldID.isValid, pInfo->lastLocation.isValidCoordinate); KNI_SetDoubleField(locationInfo, locationInfoFieldID.latitude, pInfo->lastLocation.latitude); KNI_SetDoubleField(locationInfo, locationInfoFieldID.longitude, pInfo->lastLocation.longitude); KNI_SetFloatField(locationInfo, locationInfoFieldID.altitude, pInfo->lastLocation.altitude); KNI_SetFloatField(locationInfo, locationInfoFieldID.horizontalAccuracy, pInfo->lastLocation.horizontalAccuracy); KNI_SetFloatField(locationInfo, locationInfoFieldID.verticalAccuracy, pInfo->lastLocation.verticalAccuracy); KNI_SetFloatField(locationInfo, locationInfoFieldID.speed, pInfo->lastLocation.speed); KNI_SetFloatField(locationInfo, locationInfoFieldID.course, pInfo->lastLocation.course); KNI_SetIntField(locationInfo, locationInfoFieldID.method, pInfo->lastLocation.method); KNI_SetLongField(locationInfo, locationInfoFieldID.timestamp, pInfo->lastLocationTimestamp); if (pInfo->lastLocation.addressInfoFieldNumber == 0) { KNI_SetBooleanField(locationInfo, locationInfoFieldID.isAddressInfo, KNI_FALSE); } else { KNI_SetBooleanField(locationInfo, locationInfoFieldID.isAddressInfo, KNI_TRUE); for(i=0; i<pInfo->lastLocation.addressInfoFieldNumber; i++) { midp_jstring_from_pcsl_string(&pInfo->lastAddressInfo[i].data, string_obj); switch(pInfo->lastAddressInfo[i].fieldId) { case JSR179_ADDRESSINFO_EXTENSION: fid = locationInfoFieldID. AddressInfo_EXTENSION; break; case JSR179_ADDRESSINFO_STREET: fid = locationInfoFieldID. AddressInfo_STREET; break; case JSR179_ADDRESSINFO_POSTAL_CODE: fid = locationInfoFieldID. AddressInfo_POSTAL_CODE; break; case JSR179_ADDRESSINFO_CITY: fid = locationInfoFieldID. AddressInfo_CITY; break; case JSR179_ADDRESSINFO_COUNTY: fid = locationInfoFieldID. AddressInfo_COUNTY; break; case JSR179_ADDRESSINFO_STATE: fid = locationInfoFieldID. AddressInfo_STATE; break; case JSR179_ADDRESSINFO_COUNTRY: fid = locationInfoFieldID. AddressInfo_COUNTRY; break; case JSR179_ADDRESSINFO_COUNTRY_CODE: fid = locationInfoFieldID. AddressInfo_COUNTRY_CODE; break; case JSR179_ADDRESSINFO_DISTRICT: fid = locationInfoFieldID. AddressInfo_DISTRICT; break; case JSR179_ADDRESSINFO_BUILDING_NAME: fid = locationInfoFieldID. AddressInfo_BUILDING_NAME; break; case JSR179_ADDRESSINFO_BUILDING_FLOOR: fid = locationInfoFieldID. AddressInfo_BUILDING_FLOOR; break; case JSR179_ADDRESSINFO_BUILDING_ROOM: fid = locationInfoFieldID. AddressInfo_BUILDING_ROOM; break; case JSR179_ADDRESSINFO_BUILDING_ZONE: fid = locationInfoFieldID. AddressInfo_BUILDING_ZONE; break; case JSR179_ADDRESSINFO_CROSSING1: fid = locationInfoFieldID. AddressInfo_CROSSING1; break; case JSR179_ADDRESSINFO_CROSSING2: fid = locationInfoFieldID. AddressInfo_CROSSING2; break; case JSR179_ADDRESSINFO_URL: fid = locationInfoFieldID. AddressInfo_URL; break; case JSR179_ADDRESSINFO_PHONE_NUMBER: fid = locationInfoFieldID. AddressInfo_PHONE_NUMBER; break; default: fid = 0; break; } if(fid != 0) { KNI_SetObjectField(locationInfo, fid, string_obj); } } } if (pInfo->lastLocation.extraInfoSize > 0) { midp_jstring_from_pcsl_string(&pInfo->lastExtraInfo[0], string_obj); KNI_SetObjectField(locationInfo, locationInfoFieldID.extraInfoNMEA, string_obj); midp_jstring_from_pcsl_string(&pInfo->lastExtraInfo[1], string_obj); KNI_SetObjectField(locationInfo, locationInfoFieldID.extraInfoLIF, string_obj); midp_jstring_from_pcsl_string(&pInfo->lastExtraInfo[2], string_obj); KNI_SetObjectField(locationInfo, locationInfoFieldID.extraInfoPlain, string_obj); midp_jstring_from_pcsl_string(&pInfo->lastExtraInfo[3], string_obj); KNI_SetObjectField(locationInfo, locationInfoFieldID.extraInfoOther, string_obj); midp_jstring_from_pcsl_string(&pInfo->otherExtraInfoMimeType, string_obj); KNI_SetObjectField(locationInfo, locationInfoFieldID.extraInfoOtherMIMEType, string_obj); } ret = KNI_TRUE; } } return ret; }
/* JAVADOC COMMENT ELIDED */ KNIEXPORT KNI_RETURNTYPE_INT KNIDECL(com_sun_j2me_location_LocationPersistentStorage_landmarkGetNext) { jint hndl; jint landmarkID = 0; javacall_result res; javacall_landmarkstore_landmark *landmark; jfieldID fid; jint i; KNI_StartHandles(2); KNI_DeclareHandle(landmarkObj); KNI_DeclareHandle(stringObj); hndl = KNI_GetParameterAsInt(1); KNI_GetParameterAsObject(2, landmarkObj); res = javacall_landmarkstore_landmarklist_next((javacall_handle)hndl, &landmarkID, &landmark); switch (res) { case JAVACALL_OK: if (landmark != NULL) { /* landmark.name */ jsrop_jstring_from_utf16_string(KNIPASSARGS landmark->name, stringObj); KNI_SetObjectField(landmarkObj, landmarkImplFieldID.name, stringObj); /* landmark.description */ jsr179_jstring_from_utf16(KNIPASSARGS &stringObj, landmark->description); KNI_SetObjectField(landmarkObj, landmarkImplFieldID.description, stringObj); if (!landmark->isValidCoordinate) { /* landmark.isCoordinates */ KNI_SetBooleanField(landmarkObj, landmarkImplFieldID.isCoordinates, KNI_FALSE); } else { /* landmark.latitude */ KNI_SetDoubleField(landmarkObj, landmarkImplFieldID.latitude, landmark->latitude); /* landmark.longitude */ KNI_SetDoubleField(landmarkObj, landmarkImplFieldID.longitude, landmark->longitude); /* landmark.altitude */ KNI_SetFloatField(landmarkObj, landmarkImplFieldID.altitude, landmark->altitude); /* landmark.horizontalAccuracy */ KNI_SetFloatField(landmarkObj, landmarkImplFieldID.horizontalAccuracy, landmark->horizontalAccuracy); /* landmark.verticalAccuracy */ KNI_SetFloatField(landmarkObj, landmarkImplFieldID.verticalAccuracy, landmark->verticalAccuracy); /* landmark.isCoordinates */ KNI_SetBooleanField(landmarkObj, landmarkImplFieldID.isCoordinates, KNI_TRUE); } /* landmark.addressInfoFieldNumber */ KNI_SetIntField(landmarkObj, landmarkImplFieldID.numAddressInfoFields, landmark->addressInfoFieldNumber); /* landmark.isAddressInfo */ KNI_SetBooleanField(landmarkObj, landmarkImplFieldID.isAddressInfo, (landmark->addressInfoFieldNumber > 0) ? KNI_TRUE : KNI_FALSE); for (i=0; i < landmark->addressInfoFieldNumber; i++) { switch (landmark->fields[i].fieldId) { case JAVACALL_LOCATION_ADDRESSINFO_EXTENSION: fid = landmarkImplFieldID. AddressInfo_EXTENSION; break; case JAVACALL_LOCATION_ADDRESSINFO_STREET: fid = landmarkImplFieldID. AddressInfo_STREET; break; case JAVACALL_LOCATION_ADDRESSINFO_POSTAL_CODE: fid = landmarkImplFieldID. AddressInfo_POSTAL_CODE; break; case JAVACALL_LOCATION_ADDRESSINFO_CITY: fid = landmarkImplFieldID. AddressInfo_CITY; break; case JAVACALL_LOCATION_ADDRESSINFO_COUNTY: fid = landmarkImplFieldID. AddressInfo_COUNTY; break; case JAVACALL_LOCATION_ADDRESSINFO_STATE: fid = landmarkImplFieldID. AddressInfo_STATE; break; case JAVACALL_LOCATION_ADDRESSINFO_COUNTRY: fid = landmarkImplFieldID. AddressInfo_COUNTRY; break; case JAVACALL_LOCATION_ADDRESSINFO_COUNTRY_CODE: fid = landmarkImplFieldID. AddressInfo_COUNTRY_CODE; break; case JAVACALL_LOCATION_ADDRESSINFO_DISTRICT: fid = landmarkImplFieldID. AddressInfo_DISTRICT; break; case JAVACALL_LOCATION_ADDRESSINFO_BUILDING_NAME: fid = landmarkImplFieldID. AddressInfo_BUILDING_NAME; break; case JAVACALL_LOCATION_ADDRESSINFO_BUILDING_FLOOR: fid = landmarkImplFieldID. AddressInfo_BUILDING_FLOOR; break; case JAVACALL_LOCATION_ADDRESSINFO_BUILDING_ROOM: fid = landmarkImplFieldID. AddressInfo_BUILDING_ROOM; break; case JAVACALL_LOCATION_ADDRESSINFO_BUILDING_ZONE: fid = landmarkImplFieldID. AddressInfo_BUILDING_ZONE; break; case JAVACALL_LOCATION_ADDRESSINFO_CROSSING1: fid = landmarkImplFieldID. AddressInfo_CROSSING1; break; case JAVACALL_LOCATION_ADDRESSINFO_CROSSING2: fid = landmarkImplFieldID. AddressInfo_CROSSING2; break; case JAVACALL_LOCATION_ADDRESSINFO_URL: fid = landmarkImplFieldID. AddressInfo_URL; break; case JAVACALL_LOCATION_ADDRESSINFO_PHONE_NUMBER: fid = landmarkImplFieldID. AddressInfo_PHONE_NUMBER; break; default: fid = 0; break; } if (fid != 0) { /* addressInfo */ jsr179_jstring_from_utf16(KNIPASSARGS &stringObj, landmark->fields[i].data); KNI_SetObjectField(landmarkObj, fid, stringObj); } } } break; default: /* operation Failed */ KNI_ThrowNew(jsropIOException, "I/O error"); break; } KNI_EndHandles(); KNI_ReturnInt(landmarkID); }