方法1:TLocationSensor
LocationSensor1.Active:=CheckBox1.IsChecked;
procedure TTfrmEMap.LocationSensor1LocationChanged(Sender: TObject;
const OldLocation, NewLocation: TLocationCoord2D);
begin
lblJD.Text:=Newlocation.Latitude.ToString;//获取经度
lblWD.Text:=Newlocation.Longitude.ToString;//获取维度
end;
问题: 消息始终不响应.方法2:procedure TTfrmEMap.Button3Click(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对象
LocationManagerService := sharedActivitycontext.getSystemService
(TJcontext.JavaClass.LOCATION_SERVICE);
// 获得对象的java实例
fLocationManager := tjlocationmanager.Wrap
((LocationManagerService as ILocalObject).GetObjectID);
end; // use the gps provider to get current lat, long and altitude
Location := fLocationManager.getLastKnownLocation
(tjlocationmanager.JavaClass.GPS_PROVIDER);
if Location<>nil then
begin
lat:=format('%2.6f',[location.getLatitude]);
lon:=format('%2.6f',[location.getLongitude]);
Alt := format('%2.6f',[location.getAltitude]);
lblJD.Text:=lat;
lblWD.Text:=lon;
WebBrowser.Navigate(Format(LGoogleMapURL, [Lat, Lon]));
end
end;
问题 Location 始终nil
哪位做过,帮忙指正下啊.
LocationSensor1.Active:=CheckBox1.IsChecked;
procedure TTfrmEMap.LocationSensor1LocationChanged(Sender: TObject;
const OldLocation, NewLocation: TLocationCoord2D);
begin
lblJD.Text:=Newlocation.Latitude.ToString;//获取经度
lblWD.Text:=Newlocation.Longitude.ToString;//获取维度
end;
问题: 消息始终不响应.方法2:procedure TTfrmEMap.Button3Click(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对象
LocationManagerService := sharedActivitycontext.getSystemService
(TJcontext.JavaClass.LOCATION_SERVICE);
// 获得对象的java实例
fLocationManager := tjlocationmanager.Wrap
((LocationManagerService as ILocalObject).GetObjectID);
end; // use the gps provider to get current lat, long and altitude
Location := fLocationManager.getLastKnownLocation
(tjlocationmanager.JavaClass.GPS_PROVIDER);
if Location<>nil then
begin
lat:=format('%2.6f',[location.getLatitude]);
lon:=format('%2.6f',[location.getLongitude]);
Alt := format('%2.6f',[location.getAltitude]);
lblJD.Text:=lat;
lblWD.Text:=lon;
WebBrowser.Navigate(Format(LGoogleMapURL, [Lat, Lon]));
end
end;
问题 Location 始终nil
哪位做过,帮忙指正下啊.
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货