Google Maps, No Option for Starting the Navigation, Only Preview Is There

turn-by-turn navigation with google maps url scheme swift

I found the answer as only preview button was available instead of start navigation. Because I was giving start coordinates not of my current location. So in case it is my current coordinates it will work.

Google Maps, No Option for Starting the Navigation, Only Preview is there

Auto start navigation with React Native Google Maps Directions package

The react-native-maps-directions uses the Directions API to display routes. Please note that Directions API doesn't include any real-time navigation, it is meant only to show routes. The real-time navigation additionally is prohibited in the Google Maps APIs.

Have a look at the Google Maps API Terms of Service paragraph 10.4 (c, iii). It reads

No navigation. You will not use the Service or Content for or in connection with (a) real-time navigation or route guidance; or (b) automatic or autonomous vehicle control.

source: https://developers.google.com/maps/terms#10-license-restrictions

In order to be compliant with Google Maps API Terms of Service you should open the Google Maps app installed in your device using the Google Maps URLs in navigation mode.

var url = "https://www.google.com/maps/dir/?api=1&travelmode=driving&dir_action=navigate&destination=Los+Angeles";
Linking.canOpenURL(url).then(supported => {
if (!supported) {
console.log('Can\'t handle url: ' + url);
} else {
return Linking.openURL(url);
}
}).catch(err => console.error('An error occurred', err));

I hope this helps!

Launching Google Maps Directions via an intent on Android

You could use something like this:

Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
Uri.parse("http://maps.google.com/maps?saddr=20.344,34.34&daddr=20.5666,45.345"));
startActivity(intent);

To start the navigation from the current location, remove the saddr parameter and value.

You can use an actual street address instead of latitude and longitude. However this will give the user a dialog to choose between opening it via browser or Google Maps.

This will fire up Google Maps in navigation mode directly:

Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("google.navigation:q=an+address+city"));

UPDATE

In May 2017 Google launched the new API for universal, cross-platform Google Maps URLs:

https://developers.google.com/maps/documentation/urls/guide

You can use Intents with the new API as well.

Get current location start point to uri to start navi

Maybe the dir_action=navigate parameter setting will be close to what you want.

In the official Google Maps documentation, the section on Forming the Directions URL in Developer Guide talks about how to navigate using Intent.There are dir_action=navigate and waypoints in parameters to set the navigation mode and intermediate waypoint settings. If you need to start from the user's starting point, then the origin parameter can be (original to most relevant starting location, such as user location, if available.)

https://www.google.com/maps/dir/?api=1¶meters

origin: Defines the starting point from which to display directions. Defaults to most relevant starting location, such as user location, if available. If none, the resulting map may provide a blank form to allow a user to enter the origin.

dir_action=navigate (optional): Launches either turn-by-turn navigation or route preview to the specified destination, based on whether the origin is available. If the user specifies an origin and it is not close to the user's current location, or the user's current location is unavailable, the map launches a route preview. If the user does not specify an origin (in which case the origin defaults to the user's current location), or the origin is close to the user's current location, the map launches turn-by-turn navigation. Note that navigation is not available on all Google Maps products and/or between all destinations; in those cases this parameter will be ignored.

waypoints: Specifies one or more intermediary places to route directions through between the origin and destination. Multiple waypoints can be specified by using the pipe character (|) to separate places (for example, Berlin,Germany|Paris,France). The number of waypoints allowed varies by the platform where the link opens, with up to three waypoints supported on mobile browsers, and a maximum of nine waypoints supported otherwise. Waypoints are displayed on the map in the same order they are listed in the URL. Each waypoint can be either a place name, address, or comma-separated latitude/longitude coordinates. Strings should be URL-escaped, so waypoints such as "Berlin,Germany|Paris,France" should be converted to Berlin%2CGermany%7CParis%2CFrance.

Examples from your data:

Intent intent = new Intent(Intent.ActionView, Android.Net.Uri.Parse("https://www.google.com/maps/dir/?api=1&origin=48.8276261,2.3350114&destination=48.8417122,2.3028844&waypoints=48.8476794,2.340595|48.8550395,2.300022&travelmode=driving&dir_action=navigate"));
StartActivity(intent);

If want defaulf from current location:

Uri is : "https://www.google.com/maps/dir/?api=1&origin=&destination=48.8417122,2.3028844&waypoints=48.8476794,2.340595|48.8550395,2.300022&travelmode=driving&dir_action=navigate"

Here's an official method to help you test if your destination is within planning and automatically start from your current location:

Android.Net.Uri gmmIntentUri = Android.Net.Uri.Parse("google.navigation:q=48.8417122,2.3028844");
Intent mapIntent = new Intent(Intent.ActionView, gmmIntentUri);
mapIntent.SetPackage("com.google.android.apps.maps");
StartActivity(mapIntent);

You can modify q=48.8417122,2.3028844 to your want test destination data.

If want to modify location of simulator , look at the screenshot below:

Sample Image
Sample Image

Is it possible to embed Google Navigation in an Android app?

If you are still interested in knowing about this after 2 years.
Short answer: Yes (with a but).

If you are asking about displaying a full Navigation experience with turn by turn instructions, a puck, routines on Google Maps, then the answer is: It's illegal to do it without Google's permission. If you look at the Lyft app for drivers, they do have a full navigation experience on top of Google Maps because they partnered with them. So, it's possible, but requires direct communication with Google engineers.

For a workaround, you could show an embed Google Maps view in your apps, and show Markers, Polylines. They also have these APIs to get directions from one place to the other one. For example:

https://maps.googleapis.com/maps/api/directions/json?origin=Disneyland&destination=Universal+Studios+Hollywood4&key=<YOUR_API_KEY>

NOTE: Fees will apply when using these APIs. Check their documentation for more details about the workaround.

Open Google Maps app if available with flutter

I found my issue: this needs to be in the plist file. The code in the question above is fine. (The SO answer referenced in the question only mentioned the "comgooglemaps" string.)

<key>LSApplicationQueriesSchemes</key>
<array>
<string>googlechromes</string>
<string>comgooglemaps</string>
</array>

Docs: https://developers.google.com/maps/documentation/ios-sdk/start#step_7_declare_the_url_schemes_used_by_the_api

Google map in flutter doesn't appear

Actually I didn't find any answer through my search for issues in above tutorial. I find another way for map and it works fine with my so I'll post it, as it may help others.
you need to 1- add it in pubspec.yaml to get plugin . 2- add the key for android and Ios
3- add this code in main.

import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
GoogleMapController myMapController;
final Set<Marker> _markers = new Set();
static const LatLng _mainLocation = const LatLng(25.69893, 32.6421);
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Maps With Marker'),
backgroundColor: Colors.blue[900],
),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Expanded(
child: GoogleMap(
initialCameraPosition: CameraPosition(
target: _mainLocation,
zoom: 10.0,
),
markers: this.myMarker(),
mapType: MapType.normal,
onMapCreated: (controller) {
setState(() {
myMapController = controller;
});
},
),
),
],
)));
}

Set<Marker> myMarker() {
setState(() {
_markers.add(Marker(
// This marker id can be anything that uniquely identifies each marker.
markerId: MarkerId(_mainLocation.toString()),
position: _mainLocation,
infoWindow: InfoWindow(
title: 'Historical City',
snippet: '5 Star Rating',
),
icon: BitmapDescriptor.defaultMarker,
));
});

return _markers;
}
}


Related Topics



Leave a reply



Submit