先上源码,在解释。
- implementation
-
- uses androidapi.jni.JavaTypes, androidapi.jni.Location, FMX.helpers.android,
- androidapi.jni.GraphicsContentViewText, androidapi.jnibridge;
- {$R *.fmx}
-
- procedure TForm1.Button1Click(Sender: TObject);
- const
- LGoogleMapURL: string = ‘https://maps.google.com/maps?q=%s,%s&output=embed‘;
- var
- LocationManagerService: JObject;
- Location: JLocation;
- fLocationManager: JLocationManager;
-
- Lat: string;
- Lon: string;
- Alt: string;
- begin
- if not assigned(fLocationManager) then
- begin
- LocationManagerService := sharedActivitycontext.getSystemService
- (TJcontext.JavaClass.LOCATION_SERVICE);
- fLocationManager := tjlocationmanager.Wrap
- ((LocationManagerService as ILocalObject).GetObjectID);
- end;
- Java的方法。
-
- Location := fLocationManager.getLastKnownLocation
- (tjlocationmanager.JavaClass.GPS_PROVIDER);
- lat:=format(‘%2.6f‘,[location.getLatitude]);
- lon:=format(‘%2.6f‘,[location.getLongitude]);
- Alt := format(‘%2.6f‘,[location.getAltitude]);
- edit1.Text:=lat;
- edit2.Text:=lon;
- WebBrowser1.Navigate(Format(LGoogleMapURL, [Lat, Lon]));
- end;
-
- end.
通过JNI调用Java服务,基本就是这个步骤。
http://blog.csdn.net/syndicater/article/details/18548817
xe5 for android 地理定位GPS
原文:http://www.cnblogs.com/findumars/p/6358488.html