首页 > 移动平台 > 详细

xe5 for android 地理定位GPS

时间:2017-01-30 23:37:11      阅读:327      评论:0      收藏:0      [点我收藏+]

先上源码,在解释。

[delphi] view plain copy
 
 print?技术分享技术分享
  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?技术分享技术分享
  1.     LocationManagerService := sharedActivitycontext.getSystemService  
  2.       (TJcontext.JavaClass.LOCATION_SERVICE);  
  3. // 获得对象的java实例  
[delphi] view plain copy
 
 print?技术分享技术分享
  1. fLocationManager := tjlocationmanager.Wrap  
  2.   ((LocationManagerService as ILocalObject).GetObjectID);  
  3.  end;  
  4. Java的方法。  
[delphi] view plain copy
 
 print?技术分享技术分享
  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

xe5 for android 地理定位GPS

原文:http://www.cnblogs.com/findumars/p/6358488.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!