有delphi的代碼,一般是從JLocationListener繼承后在它的onLocationChanged中獲取位置資訊。
如:
TLocationListener = class(TJavaLocal, JLocationListener)
public
constructor Create(AParent: TForm2);
procedure onLocationChanged(Location: JLocation); cdecl;
procedure onProviderDisabled(provider: JString); cdecl;
procedure onProviderEnabled(provider: JString); cdecl;
procedure onStatusChanged(provider: JString; status: Integer;
extras: JBundle); cdecl;
end;
但是我將其轉換為C++Builder:
class TLocationListener : public TJavaLocal, public JLocationListener
{
public:
void __cdecl onLocationChanged(_di_JLocation location);
void __cdecl onProviderDisabled(Androidapi::Jni::Javatypes::_di_JString provider);
void __cdecl onProviderEnabled(Androidapi::Jni::Javatypes::_di_JString provider);
void __cdecl onStatusChanged(Androidapi::Jni::Javatypes::_di_JString provider, int status, Androidapi::Jni::Os::_di_JBundle extras);
};
等到用時卻編譯錯誤:
TLocationListener *pLocationListener = new TLocationListener();//報錯:allocating an object of abstract class type
哪位高人用過,請求指點。
uj5u.com熱心網友回復:
void __fastcall TForm1::LocationSensor1LocationChanged(TObject *Sender,const TLocationCoord2D &OldLocation, const TLocationCoord2D &NewLocation)
{
lbLatitude->Text = String().sprintf(L"%2.5f", NewLocation.Latitude); //顯示緯度
lbLongitude->Text = String().sprintf(L"%2.5f", NewLocation.Longitude); //顯示經度
}
uj5u.com熱心網友回復:
謝謝,但我不想用TLocationSensor,而是想用JNI 的Location。uj5u.com熱心網友回復:
造成這個錯誤的原因,是因為“父類里的虛函式子類沒有實作。”你這個類是繼承來的,你看看父類里面的虛函式,有哪些
uj5u.com熱心網友回復:
謝謝,出錯的原因也知道。按delphi原始碼,TJavaLocal就是多載其他虛函式的,所以TLocationListener = class(TJavaLocal, JLocationListener)這樣繼承。只是CBUILDER里卻不能,哪位高人能指點一下正確用法。uj5u.com熱心網友回復:
使用LocationSensor控制元件的LocationChanged事件官方原始碼:
先LocationSensor1->Active =true;
void __fastcall TForm44::LocationSensor1LocationChanged(TObject *Sender, const TLocationCoord2D &oldLocation, const TLocationCoord2D &newLocation)
{
auto lDecSeparator = FormatSettings.DecimalSeparator;
auto lSettings = FormatSettings;
FormatSettings.DecimalSeparator = '.';
// Show current location
ListBoxItemLatitude->ItemData->Detail = ListBoxItemLatitude->ItemData->Detail.sprintf(L"%2.6f", newLocation.Latitude);
ListBoxItemLongitude->ItemData->Detail = ListBoxItemLongitude->ItemData->Detail.sprintf(L"%2.6f", newLocation.Longitude);
}
移動設備的經度和緯度,要使用反向地理編碼轉換為可讀地址
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/105715.html
標籤:基礎類
上一篇:為什么擦除背景就不行,不理解
下一篇:求c++字串基本函式
