2016-08-03 3 views
0

다음 코드를 사용하여 myFrame (Google Maps API V2)을 autoCompleteFragment (Google Places API)에서 선택한 위치로 업데이트하려고했지만 마커는 잘 바뀌지 만 카메라는 켜져 있습니다. 이전 위치.onPlaceSelected() 후 moveCamera가 작동하지 않습니다

PlaceAutocompleteFragment autocompleteFragment=(PlaceAutocompleteFragment)getFragmentManager().findFragmentById(R.id.autoComplete); 
    autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() { 
     @Override 
     public void onPlaceSelected(Place place) { 
      LatLng autoCompleteLatLng=place.getLatLng(); 
      Location newLoc=new Location("New"); 
      newLoc.setLatitude(autoCompleteLatLng.latitude); 
      newLoc.setLongitude(autoCompleteLatLng.longitude); 
      onLocationChanged(newLoc); 
     } 

private void handleNewLocation(Location location){ 
    double currentLatitude = location.getLatitude(); 
    double currentLongitude = location.getLongitude(); 
    LatLng latLng = new LatLng(currentLatitude, currentLongitude); 
    MarkerOptions options = new MarkerOptions() 
      .position(latLng) 
      .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_MAGENTA)); 
    map.addMarker(options); 
    map.moveCamera(CameraUpdateFactory.newLatLng(latLng)); 
    map.animateCamera(CameraUpdateFactory.zoomTo(10.0f)); 
} 

@Override 
public void onLocationChanged(Location location){ 
    handleNewLocation(location); 
} 

답변

0

프로젝트를 디버깅하고 중단 점을 설정하여 handleNewLocation 메서드가 실행 중인지 확인하십시오. 그런 다음 myLocation 개체에 유효한 위도 및 경도 값이 있는지 확인해야합니다. null 인 경우 카메라가 움직이지 않습니다.

여기에 관련을 그래서 티켓, 당신은 주변 지역 사회에 의해 주어진 작업 사용하려고 할 수 있습니다 : Android google map v2 moveCamera doesn't work

+0

내가 그 시도를하지만 여전히 작동하지 않습니다. 내가 디버그를 위해 som 로그를 두었고 bot에 정확한 lat와 long이 있지만 카메라를 업데이트하지는 않습니다. –