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+sql数据库增加,删除,修改,查询操作

Delphi of 打坐与普通攻击calll调用

Delphi firemonkey 图片显示拉伸不变形

adoquery 实现获取数据库所有表名

Delphi 检测一个网络连接是否有效带超时

Delphi中查找指定文件的例程

Delphi 10.3 断点全部失效

strpcopy 将字符串复制到字符数组中

orangeui作者开源作品

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



打赏

取消

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

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

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

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

评论

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