xe5 for android 地理定位GPS

先上源码,在解释。

[delphi] view plain copy
 
 print?在CODE上查看代码片派生到我的代码片
  1. implementation  
  2.   
  3. uses androidapi.jni.JavaTypes, androidapi.jni.Location, FMX.helpers.android,  
  4.   androidapi.jni.GraphicsContentViewText, androidapi.jnibridge;  
  5. // context在android的content.context包  
  6. // ILocalObject在androidapi.jnibridge里  
  7. // sharedActivitycontext在fmx.helpers里  
  8. {$R *.fmx}  
  9.   
  10. // 用android的地理GPS定位函数  
  11. procedure TForm1.Button1Click(Sender: TObject);  
  12. const  
  13.   LGoogleMapURL: string = 'https://maps.google.com/maps?q=%s,%s&output=embed';  
  14. var  
  15.   LocationManagerService: JObject;  
  16.   Location: JLocation;  
  17.   fLocationManager: JLocationManager;  
  18.   
  19.   Lat: string;  
  20.   Lon: string;  
  21.   Alt: string;  
  22. begin  
  23.   if not assigned(fLocationManager) then  
  24.   begin  
  25. //获得Java对象  
[delphi] view plain copy
 
 print?在CODE上查看代码片派生到我的代码片
  1.     LocationManagerService := sharedActivitycontext.getSystemService  
  2.       (TJcontext.JavaClass.LOCATION_SERVICE);  
  3. // 获得对象的java实例  
[delphi] view plain copy
 
 print?在CODE上查看代码片派生到我的代码片
  1. fLocationManager := tjlocationmanager.Wrap  
  2.   ((LocationManagerService as ILocalObject).GetObjectID);  
  3.  end;  
  4. Java的方法。  
[delphi] view plain copy
 
 print?在CODE上查看代码片派生到我的代码片
  1.   // use the gps provider to get current lat, long and altitude  
  2.   Location := fLocationManager.getLastKnownLocation  
  3.     (tjlocationmanager.JavaClass.GPS_PROVIDER);  
  4.     lat:=format('%2.6f',[location.getLatitude]);  
  5.     lon:=format('%2.6f',[location.getLongitude]);  
  6.     Alt := format('%2.6f',[location.getAltitude]);  
  7.     edit1.Text:=lat;  
  8.     edit2.Text:=lon;  
  9.    WebBrowser1.Navigate(Format(LGoogleMapURL, [Lat, Lon]));  
  10. end;  
  11.   
  12. end.  

通过JNI调用Java服务,基本就是这个步骤。

 

http://blog.csdn.net/syndicater/article/details/18548817

posted @ 2017-01-30 23:10  findumars  Views(363)  Comments(0Edit  收藏  举报