0

What I need to do is just open and send an string to IOS native map. The string contains the adress.

I found this code that work fine on android, but just doesn't work on IOS, why?

function OpenNavigation(const Q: string; const Coord: TLocationCoord2D): Boolean;
var
  CoordString: String;
begin
  //Open in Google Maps
  {$IFDEF ANDROID}
  exit(OpenURL('http://maps.google.com/?q=' + Q));
  {$ELSE}

  //In iOS, if Google Maps is installed, use it, otherwise, use Apple Maps
  //If we have coordinates, use them as the start address
  {$IFDEF IOS}
  exit(OpenURL('http://maps.apple.com/?daddr=' + Q));
  //Get a string of the longitute and latitute seperated by a comma if set
  if (Coord.Latitude <> 0.0) or (Coord.Longitude <> 0.0) then
  begin
    CoordString := Coord.Latitude.ToString + ',' + Coord.Longitude.ToString;
  end
  else begin
    CoordString := '';
  end;
  if not OpenURL('comgooglemaps://?daddr=' + Q) then
  begin
    if (0.0 < CoordString.Length) then
    begin
      exit(OpenURL('http://maps.apple.com/?daddr=' + Q + '&saddr=loc:' + CoordString));
    end
    else begin
      exit(OpenURL('http://maps.apple.com/?daddr=' + Q));
    end;
  end
  else begin
    exit(true);
  end;
  {$ELSE}
  //Unsupported platform
  exit(false);
  {$ENDIF IOS}
  {$ENDIF ANDROID}
end;

EDIT: The version that I'm using is RadStudio 10.1 Berlin

EDIT²: I changed twice the tag 'dictionary' to 'map' but change back to dictionary idk why.

Diego Bittencourt
  • 595
  • 10
  • 28

2 Answers2

1

To open Maps App from another iOS App, you can do following :

UIApplication.sharedApplication().openURL(NSURL(string: "http://maps.apple.com/?address=yourAddressHere")!)

You can also get CLLocation location using CLGeocoder

Please also look into this stack overflow's answer for further details.

Community
  • 1
  • 1
Munahil
  • 2,381
  • 1
  • 14
  • 24
  • Thanks dude, but this code doesn't work on Firemonkey, this is Swift i guess. Thanks anyway... – Diego Bittencourt Nov 04 '16 at 11:33
  • 1
    I have no experience in FireMonkey, but may be you can change the url to access maps, and use "http://maps.apple.com/?address=yourAddressHere" Also have al look into this http://stackoverflow.com/questions/23877683/how-can-i-launch-the-navigation-app-on-ios-and-android-with-rad-studio-firemonke – Munahil Nov 04 '16 at 11:40
  • Didn't worked. I don't know what to do anymore, I can't find an answer on the internet. That's discouraging... – Diego Bittencourt Nov 04 '16 at 16:37
0

I found the answer:

OpenURL('http://maps.apple.com/?daddr=YourAddress');
Diego Bittencourt
  • 595
  • 10
  • 28