How do I Access Maps on iOS?
This lesson describes how to use the launch url command to access Google Maps. Reference on how to use native controls for accessing Google Maps are also provided.
Accessing maps on a mobile device can be pretty useful, especially if you are out and about or you find yourself lost in an unknown location. You can provide access to Google Maps from LiveCode, using launch url or native controls.
Native controls allow you to access web pages from within your LiveCode application. An implementation of this is covered in lesson: How do I use the Browser Control?. You can easily update this lesson to embed access to Google Maps. Try entering URL: http://maps.google.com into the text field and navigate around Google Maps.
If you do not want to embed the display of maps in your LiveCode application but would prefer to launch maps in a separate application that is installed on your mobile device, then you can use the launch url command. This command attempts to open the specified URL using an application that is already installed on the device. If an appropriate application is found, then the URL to be launched is passed to the application and your LiveCode application is exited. If no suitable application can be found, then a message is sent back to the LiveCode application, allowing you to handle the failed request.
Creating the Launch Button
Launching a web page or Google Maps from within LiveCode requires only a very few lines of code:
launch url "http://maps.google.com"
if the result is "no association" then
answer "An application could not be launched for the requested url." with "Okay"
// there is no need to continue here
// a successful launch would terminate the LiveCode application
For demonstration purposes, this code is located in a button, as is shown in the figure of this step. If launch url was not able to resolve the URL request, the LiveCode application will raise a dialogue box indicating that the launch request failed. In this example, launch url is passing a valid URL, which should launch the web browser application on the mobile device.