Android - To draw a route between two geo points - android

In my direction class I have two geo points.One corresponds to current position and other is a fixed geo point.Current position will keeps changing.I need to draw route between these two points and need to change this line for a change in distance of 500m.

I think best solution is called android internal map activity to show route between two geo points . Please refer below code.
String uri = "http://maps.google.com/maps?saddr=" + currentLatitude+","+currentLongitude+"&daddr="+fixedLatitude+","+fixedLongitude;
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);
It called built in map activity and draw a route path between current and fixed latitude and longitude.

#Siraj May be this link will help you to find how you can achieve your goal .you can use your start point and End point lat and long to draw path in your own map .use this link for Geocoding API click here
For Draw path refer this link for Draw Path

Related

Get current location start point to uri to start navi

I finally found out on how to add more locations to my route in uri:
Example:
Intent intent = new Intent(Intent.ActionView, Android.Net.Uri.Parse("https://www.google.com/maps/dir/48.8276261,2.3350114/48.8476794,2.340595/48.8550395,2.300022/48.8417122,2.3028844"));
StartActivity(intent);
The problem is that I only see Preview button and not Start to start navigate.
I think it's due to the fact that the first point is not the current location.
Does anyone knows how to set up the first point as the starting point where I am currently, to have the possibility to start navigation?
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&parameters
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:
You can use this:
String mapsUrl = "https://www.google.com/maps/dir/?api=1&origin=48.8276261,2.3350114&destination=48.8476794,2.340595&waypoints=48.8550395,2.300022|48.8417122,2.3028844&travelmode=driving&dir_action=navigate";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(mapsUrl));
startActivity(intent);
Where
origin is your starting point
destination is your ending point
waypoints is your stops
you should add waypoint with using |
example: waypoints=48.8550395,2.300022|48.8417122,2.3028844
You can also add travelmode to specify travel mode
These are travel modes that you can use: driving,bicycling,transit,walking
This will open Google Maps in driving mode

Skobler Android: How can I get all points to simulated route?

I need to get many points of simulated route. My goal is get all points to paint a route using shape with SKPolyline in another view. How can I get that?
Regards.
If i understand your goal you want to draw the route that skobbler calculate for you using SKPolyline.
After request route calculation the callback onRouteCalculationCompleted will call with SKRouteInfo.
To get the route positions try:
List<SKExtendedRoutePosition> list = SKRouteManager.getInstance().getExtendedRoutePointsForRoute(skRouteInfo.getRouteID());
Don't forget to set ExtendedPointsReturned=true when you request route calculation.
SKRouteSettings routeS = new SKRouteSettings();
routeS.setStartCoordinate(startPosition.getCoordinate());
routeS.setDestinationCoordinate(destinationPosition.getCoordinate());
// number of alternative routes specified here
routeS.setNoOfRoutes(1);
routeS.setRouteMode(SKRouteSettings.SKRouteMode.CAR_FASTEST);
//set true if you want the route is draw on map
routeS.setRouteExposed();
routeS.setExtendedPointsReturned(true);
SKRouteManager.getInstance().calculateRoute(routeS);
etzuk's answer is correct, but remember to cached the route before you can get all the skPosition of created route.
On onRouteCalculationCompleted, add saveRouteToCahce before getting route's coordinates like this:
SKRouteManager.getInstance().saveRouteToCache(skRouteInfo.getRouteID());
List<SKExtendedRoutePosition> coordinatesForRoute = SKRouteManager.getInstance()
.getExtendedRoutePointsForRoute(
skRouteInfo.getRouteID());

Set an Image on the Current Location

Since the last two weeks i am developing a Navigation App.
I want to set an Pointer that is showing me the current Location.
How I can make this without using the Marker ? Or did I have to use the Marker ?
If you want to display the current location, you can use one of the following osmdroid Overlays:
MyLocationOverlay or MyLocationNewOverlay: handling GPS positionning
Or DirectedLocationOverlay: GPS position/direction/precision to handle yourself.
By the way, Marker(MapView) should be defined... Your OSMBonusPack lib is probably not installed properly.
Marker startMarker = new Marker(mapView);
startMarker.setPosition(gp);
startMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
mapView.getOverlays().add(startMarker);
mapView.invalidate();
startMarker.setIcon(getResources().getDrawable(R.drawable.iconcurrentlocation));
startMarker.setTitle("Start point");
with this one u can set immag on yout cuurentLocation and the Important thing is that you have to import this
import org.osmdroid.bonuspack.overlays.Marker;
I hope this helps somebody

showing multiple point with description in map

I am working on a cross platform app both for android and iOS. I am using phonegap as bridge between HTML5 and android/iOS.
In my database there is multiple geo point(latitude& longitude). It is easy to show a point in the map by below
//Javascript//collecting data from database with JSON
var map = new GoogleMap();
map.initialize("map_home_location",data[0].home_lat,data[0].home_lng);
////HTML5
<div class="rhtForm" style="height:250px;" id="map_home_location"></div>
One geo location point is showing properly.
But i want to show
1) multiple geo location point in a map with short description of each point.
2) When click into a point long description will show.
here description means other information stored with specific geo location point.
Thanks in advance.
Marker newMark =
map.addMarker(new MarkerOptions()
.position(lat,lng)
.title("title")
.snippet("short desc"));
Then you have the marker you just added in an object to modify if you want. Otherwise you cab just use add marker. The title and snippet pop up on clicking the marker by default.

Android route on mapview with two points

I want to draw actual route on mapview. I have tried examples but all seem to draw a line between two points not a route. I have used below code but it will automatically draw a route.
final Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse(String.valueOf(urlString)));
intent.setClassName("com.google.android.apps.maps","com.google.android.maps.MapsActivity");
startActivityForResult(intent, 5);
I want to draw a route with my own way points in map view.

Categories

Resources