zoukankan      html  css  js  c++  java
  • xe5 for android 地理定位GPS

    先上源码,在解释。

    [delphi] view plain copy
     
     print?在CODE上查看代码片派生到我的代码片
    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?在CODE上查看代码片派生到我的代码片
    1.     LocationManagerService := sharedActivitycontext.getSystemService  
    2.       (TJcontext.JavaClass.LOCATION_SERVICE);  
    3. // 获得对象的java实例  
    [delphi] view plain copy
     
     print?在CODE上查看代码片派生到我的代码片
    1. fLocationManager := tjlocationmanager.Wrap  
    2.   ((LocationManagerService as ILocalObject).GetObjectID);  
    3.  end;  
    4. Java的方法。  
    [delphi] view plain copy
     
     print?在CODE上查看代码片派生到我的代码片
    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

  • 相关阅读:
    设置qt插件路径
    实现js与Qt程序的交互(使用QtWebkit)
    QT4与QT3的不同
    Qt5 结构及模块组成?
    最简单搜索引擎代码
    使用Bootstrap
    Lucene.Net简介和分词
    程序优化
    Host和Server的开发
    jQuery的ajax对WebApi和OData的封装
  • 原文地址:https://www.cnblogs.com/findumars/p/6358488.html
Copyright © 2011-2022 走看看