2013-04-06 1 views
4

안녕하세요, 내 앱에서 앱을 매우 잘하고 있습니다.지도 페이지가있어서 Google지도 V2를 구현했고지도를 스크롤 할 때 문제가 있습니다.지도를 스크롤하면지도의 중심점을 가져 오려고합니다. 나는를 사용했다 : 그리고 미리 감사합니다 .......Google지도 v2에서 안드로이드로지도를 스크롤 할 때 중심점을 가져 오는 방법은 무엇입니까?

참고는 그 다음이 중 하나는 그것이 도움이 될 수있는이 문제를 해결하기 위해 제안 할 수 있도록지도의 중심점을 얻는다 떠나 Google지도 V2는 관련 게시물을 올려주세요.

public class Mapview extends FragmentActivity implements OnMapClickListener, OnCameraChangeListener{ 

final int RQS_GooglePlayServices = 1; 
private GoogleMap myMap; 
Location myLocation; 
TextView tvLocInfo; 
GPSTracker gps; 
public double Latitude,Longitude; 
String Datetime, addr,RegUID; 
public String lat,longd; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.mapview); 

    tvLocInfo = (TextView)findViewById(R.id.locinfo); 

    FragmentManager myFragmentManager = getSupportFragmentManager(); 
    SupportMapFragment mySupportMapFragment = (SupportMapFragment)myFragmentManager.findFragmentById(R.id.map); 

    myMap = mySupportMapFragment.getMap(); 

    myMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); 
    myMap.setMyLocationEnabled(true); 
    myMap.setOnMapClickListener(this); 
    Projection P = myMap.getProjection(); 
    Log.e("lat", String.valueOf(Latitude)); 
    Log.e("lat", String.valueOf(Longitude)); 
    Button mDone = (Button) findViewById(R.id.button1);   
    mDone.setOnClickListener(new View.OnClickListener() { 
     @SuppressLint("SimpleDateFormat") 
     public void onClick(View v) { 

      //Toast.makeText(getBaseContext(), "latitude"+lat+""+"longitude"+longd , Toast.LENGTH_LONG).show(); 
      String timeStamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime());     
      Datetime = timeStamp.toString(); 
      Log.e("t", Datetime);    
      RegUID = Utils.RegisterUserId; 
      Log.e("t", RegUID); 
      final ProgressDialog dialog = ProgressDialog.show(Mapview.this, "", Utils.Loading, true); 
      dialog.show(); 
      Handler handler = new Handler(); 
      handler.postDelayed(new Runnable(){ 
       @SuppressWarnings("unused") 
       public void run() 
       { 
        try 
        { 
         String EMPLOYEE_SERVICE_URI = Utils.Request+"UserID="+RegUID+"&Location="+URLEncoder.encode(addr,"UTF-8")+"&Latitude="+lat+"&Longitude="+longd+"&RequestDate="+URLEncoder.encode(Datetime,"UTF-8"); 
         Log.e(EMPLOYEE_SERVICE_URI, EMPLOYEE_SERVICE_URI); 
         JSONObject JObject = Utils.getResult(EMPLOYEE_SERVICE_URI); 
         //Toast.makeText(Mapview.this,JObject.toString(), Toast.LENGTH_LONG).show(); 
         if(JObject!=null) 
         {  

          if(JObject.getBoolean("Valid")) 
          { 

           AlertDialog alertDialog = new AlertDialog.Builder(Mapview.this).create(); 
           Utils.callAlert(JObject.getString("Message"), alertDialog); 

          } 
          else 
          { 
           AlertDialog alertDialog = new AlertDialog.Builder(Mapview.this).create(); 
           Utils.callAlert(JObject.getString("Message"), alertDialog); 
          } 

         } 
         else 
         { 
          AlertDialog alertDialog = new AlertDialog.Builder(Mapview.this).create(); 
          Utils.callAlert(JObject.getString("Message"), alertDialog); 
         } 
        } 
        catch (Exception e) 
        { 
         //Toast.makeText(Mapview.this,e.toString(), Toast.LENGTH_LONG).show(); 
         Log.e("Exception", e.toString()); 
        } 
        dialog.dismiss(); 
       }//run() ends 
      }, 5000);    


     } 
    }); 


} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.main, menu); 
    return true; 
} 
@Override 
protected void onResume() { 
    // TODO Auto-generated method stub 
    super.onResume(); 

    int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext()); 

    if (resultCode == ConnectionResult.SUCCESS){ 
     Toast.makeText(getApplicationContext(), 
       "isGooglePlayServicesAvailable SUCCESS", 
       Toast.LENGTH_LONG).show(); 
    }else{ 
     GooglePlayServicesUtil.getErrorDialog(resultCode, this, RQS_GooglePlayServices); 
    } 

} 
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { 
    Log.i("test","onScroll"); 
    return false; 
} 
@Override 
public void onMapClick(LatLng point) { 
    Log.e("lat", String.valueOf(point.latitude)); 
    Log.e("lat", String.valueOf(point.longitude)); 
    Latitude =point.latitude; 
    Longitude = point.longitude; 
    lat = String.valueOf(point.latitude); 
    longd = String.valueOf(point.longitude);   
    myMap.moveCamera(CameraUpdateFactory.newLatLng(point)); 
    gps = new GPSTracker(Mapview.this); 
    // check if GPS enabled  
    if(gps.canGetLocation()) 
    { 

     Geocoder geoCoder = new Geocoder(getBaseContext(), Locale.getDefault()); 
     try { 
      List<Address> addresses = geoCoder.getFromLocation(Latitude, Longitude, 1); 
      if(addresses != null) { 
       Address returnedAddress = addresses.get(0); 
       StringBuilder strReturnedAddress = new StringBuilder(""); 
       for(int i=0; i<returnedAddress.getMaxAddressLineIndex(); i++) { 
        strReturnedAddress.append(returnedAddress.getAddressLine(i)).append("\n"); 
       } 
       addr = new String(strReturnedAddress); 
       tvLocInfo.setText(addr.toString()); 

       //Toast.makeText(getApplicationContext(), addr.toString(),Toast.LENGTH_LONG).show(); 
      } 
      else 
      { 
       Toast.makeText(getApplicationContext(), "Gps location address is unavailable please try again later", 
         Toast.LENGTH_LONG).show(); 
      } 
     } catch (IOException e) { 
      // TODO Auto-generated catch block 

      e.printStackTrace(); 
     } 
    } 
} 

@Override 
public void onCameraChange(CameraPosition arg0) { 
    // TODO Auto-generated method stub 

} 

} 

답변

7

당신은 사용할 수 있습니다 : -

myMap.setOnCameraChangedListener(this); 

그리고 청취자의이 -

onCameraChange(CameraPosition position) { 
    LatLng target = position.target; 
    // do what you need with the position here 
} 

나는 경계 중 인덱스에 대해 확실하지 않다. 그러나 기본지도 위치를 설정하면 다음과 같은 것을 사용할 수 있습니다 : -

private void setDefaultMapPosition(LatLng latLng) { 

    CameraPosition camPos = 
      new CameraPosition.Builder().target(latLng) 
      .zoom(A_DEFAULT_MAP_ZOOM) 
      .bearing(0) 
      .tilt(0) 
      .build(); 

    myMap.moveCamera(
      CameraUpdateFactory.newCameraPosition(camPos)); 

    } 
+0

이 답변 주셔서 감사합니다 ....... 나는 0.0 (내가 열 때'LatLang을 보여주는 것 매핑하는 문제가 , 0.0)'강제로 오류가있는 응용 프로그램을 종료 강제로 채권 ... – androidgeek

+0

@ Ryan, 정말 고마워, 많이 도와주세요. –

관련 문제