2012-11-21 3 views
0

필자의 논문에서 안드로이드 구글 맵을 개발 중이다. 안드로이드에서 길 찾기에 대해 물어볼 수 있는가?안드로이드 구글 맵 운전 방향

여기 내 질문입니다.

"버튼을 클릭하면 무작위로 길 찾기를 시작하여 안드로이드 Google지도에서 임의의 운전 방향을 어떻게 생성 할 수 있습니까?"

고맙습니다!.

나는 이것을 통해 Google지도를 요청했습니다.

private void parsing(GeoPoint start, GeoPoint end) throws ClientProtocolException, IOException, JSONException, URISyntaxException{ 
    HttpClient httpclient = new DefaultHttpClient(); 
    StringBuilder urlstring = new StringBuilder(); 
    urlstring.append("https://maps.googleapis.com/maps/api/directions/json?origin=") 
    .append(Double.toString((double)start.getLatitudeE6()/1E6)).append(",").append(Double.toString((double)start.getLongitudeE6()/1E6)).append("&destination=") 
    .append(Double.toString((double)end.getLatitudeE6()/1E6)).append(",").append(Double.toString((double)end.getLongitudeE6()/1E6)) 
    .append("&sensor=false"); 
    //urlstring.append("http://maps.googleapis.com/maps/api/directions/json?origin=Toronto&destination=Montreal&sensor=true"); 
    url = new URI(urlstring.toString()); 

    HttpPost httppost = new HttpPost(url); 

    HttpResponse response = httpclient.execute(httppost); 
    HttpEntity entity = response.getEntity(); 
    InputStream is = null; 
    is = entity.getContent(); 
    BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8); 
    StringBuilder sb = new StringBuilder(); 
    sb.append(reader.readLine() + "\n"); 
    String line = "0"; 
    while ((line = reader.readLine()) != null) { 
     sb.append(line + "\n"); 
    } 
    is.close(); 
    reader.close(); 
    String result = sb.toString(); 
    JSONObject jsonObject = new JSONObject(result); 
    JSONArray routeArray = jsonObject.getJSONArray("routes"); 
    JSONObject routes = routeArray.getJSONObject(0); 
    JSONObject overviewPolylines = routes.getJSONObject("overview_polyline"); 
    String encodedString = overviewPolylines.getString("points"); 
    List<GeoPoint> pointToDraw = decodePoly(encodedString); 

    //Added line: 
    mv_mapview.getOverlays().add(new RoutePathOverlay(pointToDraw)); 
} 

지도에 표시되어 있습니다.

class MapOverlay extends Overlay { 

     @Override 
     public boolean onTap(final GeoPoint p, MapView mapView) { 
      // TODO Auto-generated method stub 

      geop_Tpoint = p; 
      mcon_mapcontrol = mapView.getController(); 
      mcon_mapcontrol.animateTo(p); 

      mv_mapview.invalidate(); 

      longitude = (int)(p.getLongitudeE6()*1E6); 
      latitude = (int)(p.getLatitudeE6()*1E6); 



      new AlertDialog.Builder(ShowMap.this) 
        .setTitle("Routes") 
        .setMessage("Display Routes?") 
        .setNegativeButton("NO", 
          new DialogInterface.OnClickListener() { 

           public void onClick(DialogInterface dialog, 
             int which) { 
            // TODO Auto-generated method stub 

            textlocation.setText("Tap in the Map for Destination!"); 
            dialog.dismiss(); 


           } 
          }) 
        .setPositiveButton("YES", 
          new DialogInterface.OnClickListener() { 

           public void onClick(DialogInterface dialog, 
             int which) { 
            // TODO Auto-generated method stub 
            try{ 
             textlocation.setText(""); 
             parsing(geop_startpoint,geop_Tpoint); 
             geocodeExecuter(geop_startpoint,geop_Tpoint); 
             showButton.setEnabled(true); 


            }catch(Exception e){ 

             textlocation.setText(""+ e.getMessage()); 

            } 


           } 

          }).show(); 
      showButton.setEnabled(true); 
      return true; 
     } 

출발점은 GPS를 통해입니다 그것은 당신이지도를 Google에 방향을 물어 않는 방법에 따라 달라집니다 곳 메신저 I.

+1

이 질문은 너무 광범위합니다. 너 뭐 해봤 니? – sschrass

+0

미안하지만 내 문법은 유감 스럽다. 내 요점은 이것이다. 나는 출발점과 목적지 지점이있다. 이제 내 응용 프로그램은 JSON을 사용하여 시작 지점에서 대상 지점까지 경로를 그릴 수 있습니다. 제 질문은 어떻게하면 같은 지점으로 경로를 변경할 수 있습니까? 예를 들어 Google지도 v3에서 경로를 드래그 할 수 있지만 내가 그것을 생성하는 버튼을 사용합니다. – HaTeRs

답변

5

이것은 A에서 B 지점으로가는 길에 도움이 될 것입니다.

Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?saddr=" + startLatitude + "," + startLongitude + "&daddr=" + destlat + "," + destlon)); 
startActivity(intent); 
0

저를 줄 것이다. 당신이 문신은 소스와 대상을 지정하는 링크를 사용하여 의도를 만드는 경우 ,이 같은 것을 호출 할 수 있습니다

https://maps.google.com/maps?saddr=START_POINT&daddr=MIDDLE_POINT+to:DESTINATION_POINT 

를 이것은 또한 GPS 좌표를 받아, 당신은 또한이 같은 호출 할 수 있도록 :

https://maps.google.com/maps?saddr=START_POINT&daddr=XX.YYYYY,WW.ZZZZZ+to:DESTINATION_POINT 
을 시작과 대상이 고정 된 경우

, 당신은 이런 식으로 뭔가를 시도 할 수 있습니다 :

  • 는 GPS가 당신의 시작점 좌표를 얻기
  • ,
  • GPS 좌표 목적지
  • 위해이 곳

    A와 B 사이의 임의의 지점을 생성해야

소스 및 대상에 의해 정의 된 사각형을 초과하지 않는 좌표 (XY)의 몇 가지를 생성 받기

Google지도는 중간 지점을 옥수수 밭이나 그와 비슷한 곳에 놓으면 길 찾기에 가장 가까운 지점을 선택하기에 충분히 똑똑합니다.


UPDATE : 코드를 읽은 후 : 나는 당신의 결과를 달성하는 가장 빠른 방법은 A와 B에 대한 GPS 위치를 찾을 수 있다고 생각 를, 다음 두 및 확인이 호출 사이의 임의의 지점을 생성하십시오 -RandomPoint B-RandomPoint.

총 거리는 A-R 트립과 R-B 트립의 합계가됩니다.

중점 계산 : 첫 번째로 경계를 설정하십시오. X를 계산하려면 포인트 A의 X와 포인트 B의 X를 취하십시오. 이 시점에서 : minX가 가장 낮을 것이고 maxX가 가장 높을 것입니다 (포인트가 greenwitch 근처에있다). 이제 max와 min 사이의 무작위 부동 소수점을 생성하십시오. 이것은 사소한 작업이며 그에 대한 결과가 많습니다. 그냥 예 : How do I generate random integers within a specific range in Java?

+0

내 경우 GPS로 출발 지점을 얻었고, 목적지는지도를 두드렸다. 경로/경로를 생성하라는 메시지가 나타나는 대화 상자가 있지만 다른 경로/경로를 생성해야하는 경우 어떻게 다른 단추를 클릭하여 얻을 수 있습니까? .. 정말 고마워요. – HaTeRs

+0

내 코드를 게시 할 수 있습니까? – HaTeRs

+0

다른 질문 어떻게 중점을 계산할 수 있습니까? – HaTeRs

0

이것은 내가 자바로 변환하는 방법입니다.

public List<GeoPoint> findCoordinatesInACircle(double lat, double longi,double radius){ 



     double newLat; 
     double newLong; 

     List<GeoPoint> searchpoints = new ArrayList<GeoPoint>(); 


     double rLat=(radius/6371)*(180/Math.PI); 
     double rLon= rLat/Math.cos(longi * (Math.PI/180)); 

     for(int i =0 ; i < 181; i++){ 

      double iRad = i*(Math.PI/180); 
      newLat = lat + (rLat * Math.sin(iRad)); 
      newLong = longi + (rLon * Math.cos(iRad)); 

      GeoPoint onePoint = new GeoPoint((int)(float)(newLat),(int)(float)(newLong)); 

      if(i%pointInterval == 0){ 
       searchpoints.add(onePoint); 
      } 

     } 
     return searchpoints; 

    }