Is there a limit to the drawing path using Geocoder (Android)?

I can pave the way between two points, but if the distance is too great - more than 300 kilometers - the path is not completely drawn.

I use the following code to draw a path:

class MapOverlay extends com.google.android.maps.Overlay { Road mRoad; ArrayList<GeoPoint> mPoints; public MapOverlay(Road road, MapView mv) { mRoad = road; if (road.mRoute.length > 0) { mPoints = new ArrayList<GeoPoint>(); for (int i = 0; i < road.mRoute.length; i++) { mPoints.add(new GeoPoint((int) (road.mRoute[i][1] * 1000000), (int) (road.mRoute[i][0] * 1000000))); } int moveToLat = (mPoints.get(0).getLatitudeE6() + (mPoints.get( mPoints.size() - 1).getLatitudeE6() - mPoints.get(0) .getLatitudeE6()) / 2); int moveToLong = (mPoints.get(0).getLongitudeE6() + (mPoints.get( mPoints.size() - 1).getLongitudeE6() - mPoints.get(0) .getLongitudeE6()) / 2); GeoPoint moveTo = new GeoPoint(moveToLat, moveToLong); MapController mapController = mv.getController(); mapController.animateTo(moveTo); mapController.setZoom(8); } } @Override public boolean draw(Canvas canvas, MapView mv, boolean shadow, long when) { super.draw(canvas, mv, shadow); drawPath(mv, canvas); return true; } public void drawPath(MapView mv, Canvas canvas) { int x1 = -1, y1 = -1, x2 = -1, y2 = -1; Paint paint = new Paint(); paint.setColor(Color.GREEN); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(3); for (int i = 0; i < mPoints.size(); i++) { Point point = new Point(); mv.getProjection().toPixels(mPoints.get(i), point); x2 = point.x; y2 = point.y; if (i > 0) { canvas.drawLine(x1, y1, x2, y2, paint); } x1 = x2; y1 = y2; } } 

}

+6
android google-maps overlay shape android-maps
source share
3 answers

First of all, you should use the Google V2 Maps API instead of the old legacy V1 API

In action, create links in Google Map and Polyline:

 public class MapsActivity extends AppCompatActivity implements OnMapReadyCallback{ private GoogleMap mMap; Polyline line; //...... 

First define your waypoint list:

 List<LatLng> latLngWaypointList = new ArrayList<>(); 

Get your route, draw a polyline for the route, and then draw waypoint markers:

 class GetDirectionsAsync extends AsyncTask<LatLng, Void, List<LatLng>> { @Override protected void onPreExecute() { super.onPreExecute(); } @Override protected List<LatLng> doInBackground(LatLng... params) { List<LatLng> route = new ArrayList<>(); //populate route...... return route; } @Override protected void onPostExecute(List<LatLng> route) { if (route == null) return; if (line != null){ line.remove(); } PolylineOptions options = new PolylineOptions().width(5).color(Color.MAGENTA).geodesic(true); for (int i = 0; i < pointsList.size(); i++) { LatLng point = route.get(i); //If this point is a waypoint, add it to the list if (isWaypoint(i)) { latLngWaypointList.add(point); } options.add(point); } //draw the route: line = mMap.addPolyline(options); //draw waypoint markers: for (LatLng waypoint : latLngWaypointList) { mMap.addMarker(new MarkerOptions().position(new LatLng(waypoint.latitude, waypoint.longitude)) .title("Waypoint").icon(BitmapDescriptorFactory .defaultMarker(BitmapDescriptorFactory.HUE_VIOLET))); } } } 

Here is just an implementation of placeholder isWaypoint ():

 public boolean isWaypoint(int i) { //replace with your implementation if (i % 17 == 0) { return true; } return false; } 

The result for a route from the west coast to the east coast, about 2,500 miles:

enter image description here

The result of a smaller route:

enter image description here

Note that in this example, I also use Google Directions Api to make the route snapped to roads. For a complete example of how to use the Google Directions api, see here: fooobar.com/questions/882026 / ...

+2
source share
  • I have a google direction api you have no limit for the distance you want the route to. You have other restrictions, such as the number of requests you can make within 24 hours, etc. see here for more details.
  • Always use the latest version of google maps api and game services in the development of applications for Android.
  • Follow the manual in the api manual to make you a program so that there is less chance of an error.
  • So, you have a problem with a distance that is more than 300 km. I assume that you can easily draw a path for shorter distances, and you have no problem with it. given this condition (which you can easily do at a short distance), let's start -

Decision

  • The problem that arises when drawing a larger path is associated with a large number of waypoints, and this leads to a larger memory heap requirement for the application.
  • Thus, the android kernel provides a small amount of memory for the application while running for its memory. but this is not enough for long routes, and your application will hang or crash in the worst case.
  • The solution that worked for me is to explicitly request more memory from the Android kernel heap. You can do this in a manifest.

     <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:largeHeap="true" ......... 

    Please look at the line

    Android: largeHeap = "true"

    This is what you need to do in your code.

Hope this explanation was helpful for your problem.

0
source share

If I'm not mistaken, it’s very simple to draw a path on Google maps. Source

 var mumbai = new google.maps.LatLng(18.9750, 72.8258); var mapOptions = { zoom: 8, center: mumbai }; map = new google.maps.Map(document.getElementById('dmap'), mapOptions); directionsDisplay.setMap(map); source="18.9750, 72.8258"; destination= "18.9550, 72.8158"; source = (source1.replace(" ", ",")); destination = (destination1.replace(" ", ",")); var request = { origin: source, destination: destination, travelMode: google.maps.TravelMode.DRIVING }; directionsService.route(request, function (response, status) { if (status == google.maps.DirectionsStatus.OK) { directionsDisplay.setDirections(response); } }); 
-one
source share

All Articles