1

I use Delphi on Rad Studio 10.4 and developp for Android

I have 2 put 2 components : TLocationSensor and TMap I know how to specify to the MAP to show a specific location but I do not understand how to mak automaticly my Map open to the position where my phone is Thank's a lot if somebody could help me :) Screen copy of my Google Map view

I would like to see a more accurate map (just a few kilometers around my GPS position) and not this global map that goes as far as Africa. Google Maps recovers my GPS position (shown by the blue dot on the city of Paris (France)). Would anyone be kind enough to tell me what line of code under delphi I should add? in advance a big thank you

I have found how to do it with a TBrowserComponent but I nedd to use a TMap

3 Answers3

1

This is what I use:

  Map.Location := TMapCoordinate.Create(Latitude, Longitude);

Where Latitude and Longitude are values of Double type, obtained when the OnLocationChanged event of TLocationSensor occurs

Dave Nottage
  • 3,411
  • 1
  • 20
  • 57
1

Thanks a lot for your answer. I think that my code in the LocationSensorLocationChanged is not good because the value I get do not work

procedure TForm1.LocationSensorLocationChanged(Sender: TObject; const 
OldLocation, NewLocation: TLocationCoord2D); 
var 
  ENUSLat, ENUSLong:Double; 
begin 
  ENUSLat := NewLocation.Latitude; 
  ENUSLong := NewLocation.Longitude; 
end

and after I use :

mapCenter := TMapCoordinate.Create(ENUSLat,ENUSLong);

What code do you put in your procedure ?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Please look at my answer again. It is not the same as your code. – Dave Nottage Aug 03 '20 at 08:30
  • Hello Dave, when I put your code I have an error message undeclared identifier 'Latitude'. So I have try to declare Latitude as double So I do not have any more error message but my Map ( TMapView ) do not center..... :( – Pierre jean Aug 04 '20 at 07:43
  • Did you read this part of my answer? "Where Latitude and Longitude are values of Double type, obtained when the OnLocationChanged event of TLocationSensor occurs" – Dave Nottage Aug 04 '20 at 08:30
  • Yes I have read it of course, but when I put your code : Map.Location := TMapCoordinate.Create(Latitude, Longitude); I have an error message : undeclared identifier 'Latitude', I know that the component TLocationSensor give Latitude and Longitude when position change, do you put any code in the event procedure OnLocationChange of the component TLocationSensor ? Thank's a lot for your time – Pierre jean Aug 04 '20 at 14:52
0

You need to check some TMapView properties:

  1. LayerOptions: UserLocation
  2. ControlOptions: MyLocation

Checked these properties and you can get your user device location.

Leong
  • 229
  • 2
  • 11