Android Studio: Location Marker not showing up - android

The below code is run on an AVD. The AVD browser opens the link through an application and shows google maps, but doesn't display the marker. The browser has the below 'String url' in it's url. When I press enter the url goes to the exact location and creates the marker location. I want to have the browser automatically bring me to the marker location and display a marker without having to click on the url and press enter. Any help is appreciated.
String url = "https://maps.google.com/maps?z=10&t=m&q=loc:"+latitude+"+"+longitude+"";
Uri uri = Uri.parse(Uri.encode(url));
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);

Removed the Uri.encode(url) and it seems to work OK now.

Related

How to add marker to a specific location in Google Maps in Android Studio?

I have created a button which takes the user to a specific location on Google Maps. Here is the snippet:
String uri = String.format(Locale.ENGLISH, "geo:%f,%f", latitude, longitude);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
context.startActivity(intent);
However, the Map merely zooms to the particular location without adding a marker to the co-ordinates I have put. Can someone please help me?
Thank You.
This works for me (the 'hellothere' is a label you can replace or remove):
String uri = String.format(Locale.ENGLISH, "geo:0,0?q=%f,%f(hellothere)",latitude,longitude);
UPDATE: the geo: parameter can be 0,0 when supplying a location query.
(When testing you may want to close the Map app each test particularly if not moving the marker.)

set From location to current location in google maps android programmatically

I am creating an app where it requires opening google maps to navigate to a place in walking mode and to set source/from location to current location.
Here is the code I use.
String url = "https://maps.google.co.in/maps?q=" + destination + "&mode=walking";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(intent);
How do I set "From location" to "current location"??
Thanks.
I would suggest using a Google Maps URLs instead of the link you provided in the example. The Google Maps URLs is an official and recommended way to launch Google Maps app on mobile devices and web browsers.
Please note that if you omit the origin parameter in the Google Maps URLs, the API will use your current location if available
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. The value can be either a place name, address, or comma-separated latitude/longitude coordinates. A string should be URL-escaped.
So, you should rewrite your code as
String url = "https://www.google.com/maps/dir/?api=1&destination=" + destination + "&travelmode=walking&dir_action=navigate";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(intent);
I hope this helps!

Web intent url getting modifying automatically

I trying to a webpage link so for this I am using following code
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://example.com/privacy"));
startActivity(browserIntent);
when I click on link, it open in web browser and go to proper page, when i press again on app link and open it again web browser its URL get modifying automatically, on second click i get URL like this
"https://http//example.com/privacy" I don't why this is happening
I find bug in my code
my string file had anchor tag attached thats why new url getting added to intent
this ling had bug
<string name="txt_terms_and_conditions"><a href='https://http://example.com/privacy'>By clicking the Send OTP option,\n you agree to our Terms and Conditions</a></string>
so I removed anchor tag so it working normally

Opening directions in Google maps directly

I am using below code to open direction from current location to particular location in Google Maps.
But the code first shows me "Open With dialog" giving user choice to open with other components also. I want user to be taken directly to Google maps without giving him choice to select. How can I do that?
String uri = "https://maps.google.com/maps?f=d&daddr="+location;
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(i);
You can use the below format (not officially supported):
https://www.google.com/maps/dir/My%20location/DESTINATION_ADDRESS
OR
https://www.google.com/maps?saddr=My+Location&daddr=DESTINATION_ADDRESS
eg:
https://www.google.com/maps/dir/My%20location/world%20of%20coca%20cola
https://www.google.com/maps?saddr=My+Location&daddr=world%20of%20coca%20cola
Where DESTINATION_ADDRESS is the destination address you want to navigate to.

how to start google map for result

I want my user to enter an address. But I want the address to be confirmed with Google Map. So when the user clicks on a button to enter the address, I want to launch an Intent for Google Map where user can enter the address. But then I want the map to return the data to me. How do I do that? If I start my activity as
Uri searchUri = Uri.parse("geo:0,0?z=10&q=");
Intent mapIntent = new Intent(Intent.ACTION_VIEW,searchUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivityForResult(mapIntent,RESULT_CODE_LOCATION);
number one, will it do what I seek? Second: how do I implement onActivityResult? I need the human readable address and the lat-long.
To be clear: I want the user to enter the address through Google Map and then have the address returned to my app.
I figure it out. I have to use PlacePicker to accomplish what I seek. https://developers.google.com/places/android-api/placepicker

Categories

Resources