2016-05-04 10 views
3

In meiner benutzerdefinierten Google Maps, ziehe ich eine Route zwischen zwei Standorten (sagen Pune nach Mumbai) mit diesem URLAndroid Google Maps - Wie teilen Google Maps Route in gleiche Segmente?

https://maps.googleapis.com/maps/api/directions/json?origin=Pune&destination=Mumbai&sensor=false&mode=driving&alternatives=false 

enter image description here

Parsen diese Antwort I Anzahl der Punkte zwischen Quelle und Ziel und Speicher erhalten es in ArrayList

ArrayList<LocationModel> listAllPoints = getPoints(); 

Diese ArrayList enthält rund 2600 Punkte.

Meine Frage ist, wie kann ich diese Route in 10 gleiche Segmente, d. H. Insgesamt 11 Punkte einschließlich Quelle und Ziel teilen. So

| A | B | C | D | E | F | G | H | Ich | J |

Wo | = jeder Punkt, Zeichen = Segment

Abstand zwischen A und B, B und C, C und D sollten gleich sein.

Ich sollte in der Lage sein, dies durch Teilen von listAllPoints in 11 Teile zu tun, aber das Problem ist, dass Punkte innerhalb listAllPoints nicht gleichmäßig verstreut sind.

Jede Hilfe wird sehr geschätzt.

+0

Sie mul hinzufügen tipple Wegpunkte auf Karte mit create path? –

+0

überprüfen Sie dies möglicherweise hilfreich für Sie. http://stackoverflow.com/questions/919243/how-might-i-divide-a-google-maps-display-into-an-equal-number-of-parts –

Antwort

0

Verweisen Sie auf diesen einfachen Code.

  1. Get Document

      String url = "http://maps.googleapis.com/maps/api/directions/xml?" 
         + "origin=" + start.latitude + "," + start.longitude 
         + "&destination=" + end.latitude + "," + end.longitude 
         + "&sensor=false&units=metric&mode=driving"; 
    
    
        HttpClient httpClient = new DefaultHttpClient(); 
        HttpContext localContext = new BasicHttpContext(); 
        HttpPost httpPost = new HttpPost(url); 
        HttpResponse response = httpClient.execute(httpPost, localContext); 
        InputStream in = response.getEntity().getContent(); 
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); 
        Document document = builder.parse(in); 
    
  2. Draw line:

      ArrayList<LatLng> directionPoint = v2GetRouteDirection 
            .getDirection(document); 
          PolylineOptions rectLine = new PolylineOptions().width(10) 
            .color(Color.RED); 
    
          for (int i = 0; i < directionPoint.size(); i++) { 
           rectLine.add(directionPoint.get(i)); 
          } 
          // Adding route on the map 
          mGoogleMap.addPolyline(rectLine); 
    
  3. Punkt hinzufügen

      MarkerOptions markerOptions = new MarkerOptions(); 
          Bitmap icon = BitmapFactory.decodeResource(
            EMaps2.this.getResources(), R.drawable.pointa); 
           markerOptions 
             .icon(BitmapDescriptorFactory.fromBitmap(icon)); 
          markerOptions.position(fromPosition); 
          markerOptions.title("Point A"); 
          mGoogleMap.addMarker(markerOptions); 
    
+0

Dieser Code zeichnet einfach eine Linie auf Karte. Ich habe es schon gemacht. Wie kann ich diese Route in gleiche Segmente aufteilen? –