delphi xe5 for android 地理定位GPS  
官方Delphi 学习QQ群: 682628230(三千人)
频道

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服务,基本就是这个步骤。

推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.042287826538086 seconds