Home > Back-end >  C Builder XE7 how to use JLocationListener obtain latitude and longitude
C Builder XE7 how to use JLocationListener obtain latitude and longitude

Time:10-02

Delphi code, generally after inheritance from JLocationListener in its onLocationChanged location information,
Such as:
TLocationListener=class (TJavaLocal JLocationListener)
Public
The 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;
The end;
But I convert it to c + + Builder:
The 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);
};
Wait until it is compile error:
TLocationListener * pLocationListener=new TLocationListener ();//error: allocating an object of the abstract class type
Which tall person, request to give directions,

CodePudding user response:

Void __fastcall TForm1: : LocationSensor1LocationChanged (TObject * Sender,
Const TLocationCoord2D & amp; OldLocation, const TLocationCoord2D & amp; NewLocation)
{
LbLatitude - & gt; Text=the String (). Sprintf (L "% 2.5 f", NewLocation. Latitude);//show the latitude
LbLongitude - & gt; Text=the String (). Sprintf (L "% 2.5 f", NewLocation. Longitude);//show the longitude
}

CodePudding user response:

Thank you, but I don't want to use TLocationSensor, but want to use the Location of the JNI,

CodePudding user response:

The cause of this error, because "the parent class does not implement the virtual function in the subclass,"
This class is inherited, you look at the inside of the parent class virtual functions, what

CodePudding user response:

Thank you, also know that the reason for the error by Delphi source code, TJavaLocal is overloading other virtual functions, so TLocationListener=class (TJavaLocal JLocationListener) inheritance, but not just CBUILDER, which tall person can help me with proper use,

CodePudding user response:

Use LocationSensor controls LocationChanged events

The official source:
First LocationSensor1 - & gt; Active=true;

Void __fastcall TForm44: : LocationSensor1LocationChanged (TObject * Sender, const TLocationCoord2D & amp; OldLocation, const TLocationCoord2D & amp; NewLocation)
{
Auto lDecSeparator=FormatSettings. DecimalSeparator;
Auto lSettings=FormatSettings;
FormatSettings. DecimalSeparator=';
//Show the current location
ListBoxItemLatitude - & gt; ItemData - & gt; The Detail=ListBoxItemLatitude - & gt; ItemData - & gt; The Detail. Sprintf (L "% 2.6 f", newLocation. Latitude);
ListBoxItemLongitude - & gt; ItemData - & gt; The Detail=ListBoxItemLongitude - & gt; ItemData - & gt; Detail. Sprintf (L "% 2.6 f", newLocation Longitude);
}

The longitude and latitude of mobile equipment, to use reverse geocoding into readable address
  • Related