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 base64编码/解码及zlib压缩/解压

Delphi 如何将整数值转换为罗马数字表示形式

Delphi打开外部程序或文件

Delphi 覆盖模式处理透明

Delphi汉字简繁体转换代码

Delphi xe8 form.onshow的一个小问题

Delphi removewhitespaces 过滤字符串所有空格

floattostr 将“浮点型”转换成“字符型”

Delphi不占cpu的延时函数

Delphi通过url获取网页源码

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



打赏

取消

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

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

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

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

评论

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