delphi xe6 for android LocationSensor控件默认是优先使用网络定位,对定位精度要求高的应用我们可以修改原码直接指定GPS定位。
修改方法:
将C:Program FilesEmbarcaderoStudio14.0source tlcommonSystem.Android.Sensors.pas拷贝到自己的工程目录里
打开System.Android.Sensors.pas找到function TUIAndroidLocationSensor.DoStart: Boolean;,然后按下面的提示修改就可以了。
function TUIAndroidLocationSensor.DoStart: Boolean;
var
ProviderName : JString;
Provider : JLocationProvider;
begin
Result := False;
FPermitted := TPermission.IsPermitted(StringToJString('android.permission.ACCESS_FINE_LOCATION'));
if FPermitted then
begin
if not Assigned(FLocationListener) then
FLocationListener := TLocationListener.Create(Self);
{-----删除以下几行
if FLocationManager.isProviderEnabled(TJLocationManager.JavaClass.NETWORK_PROVIDER) then
ProviderName := TJLocationManager.JavaClass.NETWORK_PROVIDER
else
if FLocationManager.isProviderEnabled(TJLocationManager.JavaClass.GPS_PROVIDER) then
ProviderName := TJLocationManager.JavaClass.GPS_PROVIDER
else
ProviderName := TJLocationManager.JavaClass.PASSIVE_PROVIDER;
-----删除以上几行}
ProviderName := TJLocationManager.JavaClass.GPS_PROVIDER ;//增加这一行
Provider := FLocationManager.getProvider(ProviderName);
if Assigned(Provider) then
begin
FMyRunner := TLocationRunnable.Create(FLocationManager, FLocationListener, ProviderName);
FActivity.runOnUiThread(FMyRunner);
Result := True;
end;
end;
end;