I am displaying a location on Google map by passing latitude longitude values.
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("geo:0,0?q=" + (" "+dblLatitude+", "+dblLongitude+" ")));
try {
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
setContentView(R.layout.map_locate);
}
Its working fine for me. But I also want to show text on above the located point. Any idea how to pass the text dynamically like I am passing lat, long values?
To show a label on Google Maps application you have to add it in brackets after coordinates.
See this answer: https://stackoverflow.com/a/7405992/2183804
You can put extra data into the intent object using e.g. the putExtra(String,String) method on the intent object.
As you firing an intent to turn on the native Google Maps Application. I don't think that what you are trying to achieve is possible. AFAIK all you can add to the desired location is an icon.
If you want to add to it more functionality you would have to develop your own map application.
UPDATE:
To develop you own map, you can take a look at this blog post I wrote on that matter:
Google Maps API V2
If you have questions don't hesitate to ask.
Related
I am using HERE Android SDK to perform turn by turn navigation project. But I do not get the result similar to image.
I hava this code to get the current manauver
private NavigationManager.NewInstructionEventListener newInstructionEventListener = new NavigationManager.NewInstructionEventListener() {
#Override
public void onNewInstructionEvent() {
Maneuver maneuver = navigationManager.getNextManeuver();
if (maneuver != null) {
if (maneuver.getAction() == Maneuver.Action.END) {
}
tvManeuver.setText(navigationManager.getNextManeuver().getTurn().name() + " " + maneuver.getIcon().value());
ivTitle.setImageBitmap(maneuver.getNextRoadImage().getBitmap());
tvStreet.setText(maneuver.getRoadName());
tvMeters.setText("durante " + maneuver.getDistanceFromPreviousManeuver() + " m");
if (maneuver.getDistanceToNextManeuver() == 0) {
tvMeters.setVisibility(View.GONE);
} else {
tvMeters.setVisibility(View.VISIBLE);
}
}
}
};
But I do not get the correct text of the maneuver. For example "Turn right at the next corner" and the and the corresponding arrow icon to put inside IMAGEVIEW.
can anybody help me?
Regards.
I assume the image you provided is from HERE Maps available on Google Store which is a custom implementation using the HERE SDK.
The instruction you can get from Maneuver , check documentation
https://developer.here.com/mobile-sdks/documentation/android-hybrid-plus/topics_api_nlp_hybrid_plus/com-here-android-mpa-routing-maneuver.html#topic-apiref__getinstruction-void
Icon should also be retrieved from getIcon() , which gives an enumeration and you will need to create images for possible enumerations in the icon , check documentation
https://developer.here.com/mobile-sdks/documentation/android-hybrid-plus/topics_api_nlp_hybrid_plus/com-here-android-mpa-routing-maneuver-icon.html#topic-apiref
If you want to get the list of maneuvers, you can't get it on the NewInstructionEvent.
Since you are already in navigation you should already have your route object. On the route object you can just call getManeuvers(). That will give you all the list of maneuvers for the current route.
You can also refer to their UI Kit https://developer.here.com/blog/build-beautiful-interfaces-with-the-here-mobile-sdk-ui-kit-for-android-and-ios.
Hope this helps. I know this is an older thread.
HERE SDK Premium does not provide Maneuver Instructions pre- start of Navigation nor can you get a list of Maneuver Instructions at any point.
You however could get a list of Maneuver Instructions using the HERE Routing API.
https://developer.here.com/documentation/routing-api/dev_guide/topics/use-cases/actions.html
One more way is to get Instructions through the AudioPlayerDelegate.PlayText callback.
I'm pretty much on the last step to getting my app to work before I start focusing on the front-end design. As someone who just started programming just last year and haven't made any serious apps before, this is very exciting, but I hit a wall that I need help getting out of. I know this is a stretch but here goes.
I was able to use the google maps API and OSRM API with no problems using the simple URL object from java.net.URL, but that was because the APIs did not require any type of OAuth authentication.
Link
For Yelp's API, I need to use OAuth and they provide sample code located here
I copied both YelpAPI.java and TwoStepOAuth.java and the search works when I try searching by location name. However, I need to change the code to work with lat/long coordinates.
https:// www.yelp.com/developers/documentation/v2/search_api
By going to their Search API documentation, I thought that replacing:
request.addQuerystringParameter("location", location);
with
request.addQuerystringParameter("ll", coordinate);
where coordinate can be any lat/long coordinate such as
String coordinate = 34.095287, -118.1270146
However, that did not work. I'm not sure where to go at this point. I've been stuck on this issue for two days and I'm unable to find any resources online to help me. Thanks for reading.
to search yelp data by lat, lng I use the below method
public String search(String term, double latitude, double longitude) {
OAuthRequest request = new OAuthRequest(Verb.GET, "http://api.yelp.com/v2/search");
request.addQuerystringParameter("term", term);
request.addQuerystringParameter("ll", latitude + "," + longitude);
this.service.signRequest(this.accessToken, request);
Response response = request.send();
return response.getBody();
}
Now all you just need is to cast your string co-ordinates to double.
In my app, I am writing a functionality to share a shopping list to Google Keep. For this, I use the Intent.ACTION_SEND action and set the package to the one of Google Keep.
Everything works great, but I am wondering if it is possible to add an EXTRA parameter to the Intent telling Google Keep it must be displayed as a list with checkboxes, like it is possible to add extra event-specific extra's when creating a Calendar Event. Now, it is displayed as plain text.
Here is my code:
try {
Intent keepIntent = new Intent(Intent.ACTION_SEND);
keepIntent.setType("text/plain");
keepIntent.setPackage("com.google.android.keep");
keepIntent.putExtra(Intent.EXTRA_SUBJECT, "Shopping List " + recipe.getName());
keepIntent.putExtra(Intent.EXTRA_TEXT, "Flower\nyeast\nbutter\nalmonds");
startActivity(keepIntent);
} catch (Exception e) {
Dialogs.toastShort(this, "Google Keep is not installed on your device");
}
Now, I get this as result:
What, I want to get is this as result - without that the user has to select "show checkboxes" in the actionbar:
Thanks for your help.
Unfortunately, it's not possible. Google has not published an API for public nor 3rd party use. If you check out the http traffic you can see the underlying API but there's no real way to replicate it. Sorry
I know it is possible to get direction between coordinates using Google's direction web service. But is there any other way to get equally accurate route?
I found few questions on SO those use http://maps.google.com/ to get direction. But then also found few answers on other questions which state that it is no longer supported.
I am confused as this is the first time I am dealing with Google maps for android.
Is there any built in android sdk method to get direction?
you can send an intent to the google maps app and have the app do all the work for you but its not documented and probably never will be.
to do that you can either give it a lattitue/longitude like this
Intent NavIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("google.navigation:q=" +latitude +","+longitude));
startActivity(NavIntent);
or using the same intent but with an address and see if maps can resolve the address. (I dont have an example with an address).
Other than using google directions API or other 3rd party direction web services there really is no other way to get directions in your app unless you look at Open Street Maps where you calculate the directions yourself using way points but that is quite involved
Firing an intent to the google maps app is what I've choosen to use in my application, the philosophy here is that Android apps should exploit and complement each other functionnlities
Intent i = new Intent(Intent.ACTION_VIEW,Uri.parse(getDirectionUrl(srcLat, srcLng, dstLat, dstLng)));
if (isGoogleMapsInstalled(this)) {
i.setComponent(new ComponentName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity"));
}
startActivity(i);
method to build the directions URL:
public static String getDirectionUrl (double srcLat, double srcLng, double dstLat, double dstLng) {
//return google map url with directions
StringBuilder urlString = new StringBuilder();
urlString.append("http://maps.google.com/maps?f=d&saddr=")
.append(srcLat)
.append(",")
.append(srcLng)
.append("&daddr=")
.append(dstLat)
.append(",")
.append(dstLng);
return urlString.toString();
}
Method to test if Maps is installed:
public static boolean isGoogleMapsInstalled(Context c) {
try
{
#SuppressWarnings("unused")
ApplicationInfo info = c.getPackageManager().getApplicationInfo("com.google.android.apps.maps", 0 );
return true;
}
catch(PackageManager.NameNotFoundException e)
{
return false;
}
}
The downside is that Google may change the URL structure.
I am new to android and developing a navigation based application for android.My question is I want to show a route with multiple way-points between source and destination node in Google maps and I don't know how to do it. I have search for this but most of the results are for two points.
Please help me to solve my problem
e.g:- when app user submits the destination with some way-points the map should display the route from the source to destination with those way-points on the phone.
Thanks !
I don't think the Maps intent offers those capabilities, but you do have some other options
Better but more work
1)Create your own map activity that displays routes for multi-location(using a mapview and overlays). Here is an example of how to convert the kml file to a route
Quicker and Easier
2)Create a simple webview (or you can just intent a new one with a given url) and dynamically build the url for a google maps api request with waypoints. See Google's website for documentation on getting a map with routes via waypoints.
"I have search for this but most of the results are for two points." You already found everything you need to do this.
For this, you're not "drawing through the waypoints along the way," you're actually going to have to draw a route between 2 points for each waypoint you have:
IE. You want to get from point A to point D, and on the way there are points B and C. The solution is to draw a route from A to B, B to C, and finally C to D.
You can use the map intent like this:
String address = "http://maps.google.com/maps?daddr=" + "Latitude" + "," + "Longitude" + "+to:" +"Latitude" + "," + "Longitude";
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(address));
startActivity(intent);
in this case the start point will be your current location and you can add as many intermediate points as you want using "+to:"