Google maps API in Android - android

I am trying to implement a functionality such that when a user enters an address in a text field and clicks on a button, that address should be copied into the destination field of Google maps and the user location should be set to "My Location" (his current location).

You can open google map in following way:
String CURRENT_LOCATION = "current_location_latitude, current_location_longitude";
String DESTINATION_LOCATION = "address_from_your_text_view";
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr="+ CURRENT_LOCATION +" daddr="+DESTINATION_LOCATION));
startActivity(intent);
Note: You should get device/user current location from LocationManager

In order to show route on Google Map, Just call an intent which passes current and destination latitude and longitude. You may also pass address in any case if don't know lat-long. After doing this, its Google Map's job to show location. You may also show street view.
In below code, there are three parameters : current_lat, current_longi, dest_address
final Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?"
+ "saddr="+ current_lat+","+current_longi + "&daddr="+dest_address ));
intent.setClassName("com.google.android.apps.maps","com.google.android.maps.MapsActivity");
startActivity(intent);
If you have current address and destination address, then you can write like this :
Uri.parse("http://maps.google.com/maps?"
+ "saddr="+curr_address+ "&daddr="+dest_address ));
If you have current and destination latitude and longitude both then you can write like this :
Uri.parse("http://maps.google.com/maps?"
+ "saddr="+ current_lat+","+current_longi + "&daddr="+ destt_lat+","+dest_longi ));
When you call this intent, Google Map shows option whether to draw route by bus or by walk.

Related

Using Google Maps Direction Service on Android

I am trying to create an app that will launch a Google Maps Intent that will show the route to point A, passing through points B and C. I have the addresses and the LatLng of theses points.
Until now I tried to use just make a route from one pont to another using what is in this answer but it didn't work. When the Google Maps app opens it says that no route was found. The origin and destination fields are filled with the latitude and longitude of my points.
What am I doing wrong? Is there another way of doing this?
EDIT: Code I'm using to start the intent:
double ori_latitude = -90.0000000;
double ori_longitude = -60.0000000;
double dest_latitude = -90.0000000;
double dest_longitude = -54.0000000;
String uri = String.format(Locale.ENGLISH, "http://maps.google.com/dir ?saddr=%f,%f&daddr=%f,%f", ori_latitude, ori_longitude, dest_latitude, dest_longitude);
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
Just a quick glance says your code would work, but your coordinates point nowhere special, so I wouldn't be surprised if no route existed.
From a quick test, this works for me.
Seattle, WA to San Francisco, CA
double[] origin = { 47.605617, -122.332137 };
double[] dest = { 37.774821, -122.419462 };
Uri.Builder builder = new Uri.Builder()
.scheme("http")
.authority("maps.google.com/maps")
.appendQueryParameter("saddr", String.format(Locale.ENGLISH, "%f,%f", origin[0], origin[1]))
.appendQueryParameter("daddr", String.format(Locale.ENGLISH, "%f,%f", dest[0], dest[1]));
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(builder.build().toString()));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
Code you have written is correct. There is issue with these coordinates.
Try changing coordinates, and see the magic. It works perfectly.
For eg:
double ori_latitude = 34.052222;
double ori_longitude = -118.243611;
double dest_latitude = 37.322778;
double dest_longitude = -122.031944;
Also, check the rules at
Google Maps
Tips for formatting your coordinates
Here are some tips for formatting your coordinates so they work on Google Maps:
Use the degree symbol instead of "d".
Use periods as decimals, not commas.
Incorrect: 41,40338, 2,17403. Correct: 41.40338, 2.17403.
List your latitude coordinates before longitude coordinates.
Check that the first number in your latitude coordinate is between -90 and 90.
Check that the first number in your longitude coordinate is between -180 and 180.

Android - How to launch Google map intent in android app setting both zoom level and marker

My question is very similar to this question (Android - How to launch Google map intent in android app with certain location, zoom level and marker) but the accepted answer is not working for me. It opens the map with the marker at the correct place and at the correct zoom level but then proceeds to zoom in to a street level view (zoom=16 or 17?).
I've search SO, I've read through this documentation but can't find a combination of place marker & zoom that do what I need.
I've tried with a few devices using Google Maps versions
8.2.0,
9.20.1,
9.36.2 &
9.42.3
Here is the result of the log print (the Uri used for the intent)
geo:39.29038619995117,-76.61219024658203?q=39.29038619995117%2C-76.61219024658203(Baltimore)&z=11
The answer from the other post is 4 years old now. Has Maps changed such that this doesn't work now? Did the other answer only work because they were setting the zoom to 17 and didn't notice it wouldn't settle on another zoom level? Am I missing something else?
To clearly state my question:
How can I use a geo intent to open a maps app to show a place marker and simultaneously choose a zoom level?
My code, based on the accepted answer from the other post.
double latitude = item.getLatitude();
double longitude = item.getLongitude();
String label = item.getName();
String uriBegin = "geo:" + latitude + "," + longitude;
String query = latitude + "," + longitude + "(" + label + ")";
String encodedQuery = Uri.encode(query);
String uriString = uriBegin + "?q=" + encodedQuery + "&z=11";
mListener.onListFragmentInteraction(uriString);
Then
public void onListFragmentInteraction(String url) {
Uri geoLocation = Uri.parse(url);
Log.d(TAG, "geo uri = " + geoLocation);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(geoLocation);
startActivity(intent);
}
#Gary99 for removing restaurant u have to add hiding map feature content here is the link(https://developers.google.com/maps/documentation/android-api/hiding-features)
Uri gmmIntentUri = Uri.parse("geo:37.7749,-122.4194?z=10&q=restaurants")
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri)
mapIntent.setPackage("com.google.android.apps.maps")
startActivity(mapIntent)

Google Maps Intent with marker & user position

Can you launch from an APK a Google Maps intent that includes both a marker with a specific location and the user position? I've been trying to but haven't been able as of yet.
http://wptrafficanalyzer.in/blog/storing-and-retrieving-locations-in-sqlite-from-google-maps-android-api-v2/
try this site man i guess it will help.helped me though.
You can try this:
String uri = "http://maps.google.com/maps?saddr=" + latitude +","+ longitude +"&daddr=" + userLatitude + "," + userLongitude;
startActivity(new Intent(android.content.Intent.ACTION_DEFAULT, Uri.parse(uri)));

geo: Intent with label (Android)

Is there a working way (i heard that as of update 7.0 there were some changes) to display a marker with a position given by latitude/longitude with a label?
geo:?q=latitude, longitude (Label) does not work...
Show point on google map via an intent:
String uri = "geo:"+ latitude + "," + longitude;
startActivity(new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri)));
You can also choose to place a point like so:
String uri = "geo:"+ latitude + "," + longitude + "?q=my+street+address";
startActivity(new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri)));
The Possible Query params options are the following:
Show map at location: geo:latitude,longitude
Show zoomed map at location: geo:latitude,longitude?z=zoom
Show map at location with point: geo:0,0?q=my+street+address
Show map of businesses in area: geo:0,0?q=business+near+city

android Map view Issue

I have made an application containing facility of viewing current location on map. I have used default Map Intent to show map. It Works fine in Emulator but when I am testing in my Android device (motorola Millstone) , Map works fine but after view map, my application is not responding.anyone have any ideas why it happens?
String path = "http://maps.google.com/maps?saddr=" + lat + ","+ lon + "&daddr=" + b_latt + "," + b_lang;
String geoUriString = new String(path);
Uri geoUri = Uri.parse(geoUriString);
Intent mapCall = new Intent(Intent.ACTION_VIEW, geoUri);
startActivity(mapCall);
You want to show One Marker at Current Location,but In the code you shown you are passing two values to draw path..
To show user's Current Location on Map via intent you need to call this way
String uri = "geo:"+ latitude + "," + longitude;
startActivity(new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri)));
You can see More on This Site

Categories

Resources