You can send location data to the maps app on the user device to show directions. For example, if you have a location returned from an API, you can open the maps app to display directions there from the user’s current location, as outlined below.
- To access the user location, add a Page Variable of type Core Location - CLLocationManager. Request location access, for example in a Page Loaded Event, using the Request Location Authorization Action, selecting the variable.
- Create a Page Variable of type Core Location - CLLocation to store the destination location.
- Store the destination location in the
CLLocation variable, for example in an API request status code Event. If the location data is in the form of latitude and longitude, use the Create a Location Object Action to store is as a
CLLocation. Use a Set Value Action to save the location to the variable you created.
- Decide when you want to open the maps app for directions, for example when the user taps a button, in which case you would select the button, open Properties > Events, select the Tapped Event, and add an Action.
- If you’re using the user location, add a Request Location Update Action, selecting the
CLLocationManager variable.
- In the nested Location Updated Event, or the Event you’re already working in if you aren’t using the user location, add the Open Maps App for Directions Action. Select a maps app, the start location (from the Event Data if you’re using user location), and the end destination (from the
CLLocation page variable).
- If you’re using the user location, add a Request Location Update Action, selecting the
CLLocationManager variable.
If you’re using user location, you won’t be able to test the functionality in the web simulator, but you can run it on a physical device. You can show locations on a map inside your app from latitude and longitude – mapping functionality will run in the web simulator as long as the user location is not used.
You can send location data to the maps app on the user device to show directions. For example, if you have a location returned from an API, you can open the maps app to display directions there from the user’s current location, as outlined below.
- To access the user location, include a Google Maps API Key in your project Location Settings.
- Create a Page Variable of type
Location - LatLng to store the destination location.
- Decide when you want to open the maps app for directions, for example when the user taps a button, in which case you would select the button, open Properties > Events, select the Tapped Event, and add an Action.
- If you’re using the user location, add a Request Location Update Action, selecting an accuracy level.
- In the nested Location Updated Event, or the Event you’re already working in if you aren’t using the user location, add the Open Maps App for Directions Action. Select the start location (from the Event Data if you’re using user location), and the end destination (from the
LatLng page variable).
- If you’re using the user location, add a Request Location Update Action, selecting an accuracy level.
If you’re using user location, you won’t be able to test the functionality in the web simulator, but you can run it on a physical device. You can show locations on a map inside your app from latitude and longitude – mapping functionality will run in the web simulator as long as the user location is not used.