Skip to content

Latest commit

 

History

History
41 lines (19 loc) · 1.89 KB

README.md

File metadata and controls

41 lines (19 loc) · 1.89 KB

Launch Map by URI

iOS apps utilize uniform resource locators (URLs), a form of uniform resource identifiers (URIs), to communicate with system apps. By calling the OpenURL(NSUrl url) method on the main application class, it is possible to launch the Maps application already focused on a specific location.

App Screen

Map Screen

Recipe

  1. First, we must generate a NSUrl starting with the path "http://maps.apple.com/?q=" appended to the location we wish to bring up in Maps. For this example, lets place the following code in the callMap TouchUpInside event handler:

    String cityAddress = cityText.Text.Replace (' ', '+');
    			 var url = new NSUrl ("http://maps.apple.com/?q="+ cityAddress);
  2. Since the NSUrl cannot contain space characters, we replace them with '+' characters.To open Maps, we would place the following code after we generate our NSUrl variable:

    <pre><code>UIApplication.SharedApplication.OpenUrl (url);</code></pre>
    

    This code will cause the Maps application to open, searching for the location entered in the cityText UILabel.

Additional Information

There are a variety of parameters that can be appended onto "http://maps.apple.com/?" that can specify the information loaded by the Maps app. In this example, we used the query parameter, "q=", which loads the following string as if it had been typed into the query box in the Maps app. To see all available parameters, see the Apple URL Scheme Reference