how to add my location to google maps api - android

How to add source address in android for opening google maps with source and destination address?
I have tried the following:
String map ="https://maps.google.com/maps?saddr=My+Location&daddr="+address;
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(map));
i.setClassName("com.google.android.apps.maps","com.google.android.maps.MapsActivity");
startActivity(i);
I am getting error in map application as "no result for my location"
My requirement is that I want to open google maps application with user current location and destination address which i am passing.

You can try this way:
String uri = String.format(Locale.ENGLISH, "geo:0,0?q=", "ahmedabad");
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);

Related

How to show distance between two points on map

I have latitude and longutude of two points. I want to show the route between them by opening google maps from my app on button click. How to do so?
Use below code for getting show route in google map...
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("
http://maps.google.com/maps?" +"saddr=" + sourcelatLng + "&daddr=" + destlatlng;
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
If you want to open maps app with a route from your source to destination, you just need to start an activity with following intent.
Uri routeUri = Uri.parse("http://maps.google.com/maps?saddr=your-lat-1,your-lng-1&daddr=your-lat-2,your-lng-2");
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, routeUri);
startActivity(intent);
Replace your-lat/lng-1/2 with your latitude and longitude.

How to pass a list of coordinates to the default google Map Application?

From my app i am opening the default google map app. Here is how i am doing it.
String uri = String.format(Locale.ENGLISH, "geo:0,0?q=%f,%f(%s)",
locationList.get(1).getLatitude(), locationList.get(1).getLongitude(),"My location");
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
Log.i(TAG, "Uri is "+ uri);
this.startActivity(intent);
This is working fine. But is it possible to pass a list of coordinates and plot them all so i could create a path?
Here try this:
String destination = locationList.get(1).getLatitude()+","
+locationList.get(1).getLongitude();
Uri gmmIntentUri = Uri.parse("google.navigation:q="+destination+"&mode=d");
Log.e(TAG,"Intent uri : "+gmmIntentUri.toString());
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mapIntent.setPackage("com.google.android.apps.maps");
this.startActivity(mapIntent);
this will open map in navigation mode from your current location to the specified destination.
you can have a look at the below link to specify way points between your source and destination:
https://developers.google.com/maps/documentation/urls/android-intents
https://developers.google.com/maps/documentation/urls/guide
Let me know if you have any doubts.

Unable to find the place in google map using Android in specific radius

I want to find places of interest under a specific radius using Android. I am working in this way
String uri = "geo:"+ 40.007620 + "," + -75.160264 +"&q=child hospitals";
startActivity(new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri)));
But when I run the application, It opens the google maps but does not mark the child hospitals. Any wrong here?
Try this,
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("geo:<40.007620>,<-75.160264>?q=<40.007620>,<-75.160264>(child hospitals)"));
startActivity(intent);
Please check below reference which will guide you to how to pass or format map intent query data :
https://developers.google.com/maps/documentation/android-api/intents
Example :
Uri gmmIntentUri = Uri.parse("geo:40.007620,-75.160264?q=" + Uri.encode("child hospitals"));
Humty you can try to this code hope this can help you..
Uri gmmIntentUri = Uri.parse("geo:40.007620,-75.160264?z=10&q=child hospitals");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);
You can try something like this :
String urlAddress =
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=lat,lng&radius=500&type=city hospital&keyword=hospital&key=YOUR_API_KEY
which you can pass to
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlAddress);
startActivity(intent);
This will get opened in Google Maps with the results w.r.t provided radius. It works also same mentioned in below doc reference.
https://developers.google.com/places/web-service/search
Url to test :
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=18.590478,73.727191&radius=50000&type=child%20hospital&keyword=child%20hospital&key=PASTE_YOUR_API_KEY

How to stop google MapsActivity from rerouting my route?

I am using
String uri = String.format(Locale.ENGLISH, "http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f", sourceLatitude, sourceLongitude, destinationLatitude, destinationLongitude);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);
for providing navigation support in my app , but whenever I go off route than it draws a new route to the destination. How to stop it, I want the route to be fixed

google map intent not animate to current location in android app...?

I have an android application in which one place I want to call maps.google.com intent and display direction from source to destination.
But when I use this, I want maps animate to direction path automatically.
I use below for calling maps intent
String saddr = "current location";
String daddr = "other location";
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr="+ saddr+ "&daddr="+ daddr));
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
intent call properly and show me maps, and draw path as well but not animate to that place.
Check this link out:
http://developer.android.com/guide/appendix/g-app-intents.html
In your:
Uri.parse("http://maps.google.com/maps?saddr="+ saddr+ "&daddr="+ daddr)
try:
Uri.parse("http://maps.google.com/maps?saddr="+ saddr+ "&daddr="+ daddr+"&z=10")

Categories

Resources