2016-08-23 1 views

답변

0

또한 onLocationChanged 클래스를 구현해야합니까?

위치 업데이트를받지 않으려면 아니오입니다.

가장 간단한 방법은 무엇입니까?

가장 간단한 방법은 here과 같이 마지막으로 알려진 위치를 얻는 것입니다.

0

예제 Google지도 프로젝트 github에는이를 수행하는 방법의 예가 있습니다.

또한 Android Studio에는 프로젝트를 만들 때 선택할 수있는 Google지도 활동 템플릿이 있습니다. 이 프로젝트에는 getLastKnownLocation()이 구현되었습니다. 자세한 내용은 here을 참조하십시오.

1

다른 방법으로 구현할 수 있습니다. 귀하의 작업에 가장 적합한 것은 내 위치 버튼을 누른 후 토스트를 보여주는 것이라고 생각하는 경향이 있습니다.

public class MapActivity extends FragmentActivity implements OnMapReadyCallback { 
    private GoogleMap mMap; 

    /** 
    * Manipulates the map once available. 
    * This callback is triggered when the map is ready to be used. 
    * This is where we can add markers or lines, add listeners or move the camera. In this case, 
    * we just add a marker near Sydney, Australia. 
    * If Google Play services is not installed on the device, the user will be prompted to install 
    * it inside the SupportMapFragment. This method will only be triggered once the user has 
    * installed Google Play services and returned to the app. 
    */ 
    @Override 
    public void onMapReady(GoogleMap googleMap) { 
     mMap = googleMap; 

     //Show my location button 
     mMap.setMyLocationEnabled(true); 

     mMap.setOnMyLocationButtonClickListener(new GoogleMap.OnMyLocationButtonClickListener() { 
      @Override 
      public boolean onMyLocationButtonClick() { 
       //Do something with your location. You can use mMap.getMyLocation(); 
       //anywhere in this class to get user location 
       Toast.makeText(MapActivity.this, String.format("%f : %f", 
         mMap.getMyLocation().getLatitude(), mMap.getMyLocation().getLongitude()), 
         Toast.LENGTH_SHORT).show(); 
       return false; 
      } 
     }); 
    } 
} 

또한 변경 될 때마다 사용자 위치로 토스트를 표시 할 수 있습니다. 이를 위해 OnMyLocationChangeListener를 설정하십시오.

mMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() { 
     @Override 
     public void onMyLocationChange(android.location.Location location) { 
      //... 
     } 
    }); 
관련 문제