Delphi xe5 for android 地理定位GPS


本文整理自网络,侵删。

 
implementation  
  
uses androidapi.jni.JavaTypes, androidapi.jni.Location, FMX.helpers.android,  
  androidapi.jni.GraphicsContentViewText, androidapi.jnibridge;  
// context在android的content.context包  
// ILocalObject在androidapi.jnibridge里  
// sharedActivitycontext在fmx.helpers里  
{$R *.fmx}  
  
// 用android的地理GPS定位函数  
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  
//获得Java对象  
[delphi] view plain copy
    LocationManagerService := sharedActivitycontext.getSystemService  
      (TJcontext.JavaClass.LOCATION_SERVICE);  
// 获得对象的java实例  
[delphi] view plain copy
fLocationManager := tjlocationmanager.Wrap  
  ((LocationManagerService as ILocalObject).GetObjectID);  
 end;  
Java的方法。  
[delphi] view plain copy
  // use the gps provider to get current lat, long and altitude  
  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服务,基本就是这个步骤。

相关阅读 >>

Delphi 递归获取文件夹大小

Delphi 安卓app的https访问权限

Delphi xe5 给edit增加自定义按钮

Delphi通过ip或机器名获取局域网mac地址

Delphi 模似键盘输入又一方法

Delphi spcomm 接收数据不完整

Delphi通过idhttp和php交互

Delphi实时监视应用程序内存使用量

Delphi中基于内容检测图片格式(非扩展名)

Delphi 如何在在windows平台下实现进程隐藏

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...