Google지도 앱이 있으며 이제 버튼이 추가되었습니다. 버튼을 클릭하면 내 좌표로 메시지 (토스트)를 가져오고 싶습니다. 가장 간단한 방법은 무엇입니까? onLocationChanged 클래스도 구현해야합니까?버튼을 클릭 할 때 현재 위치 가져 오기
0
A
답변
0
또한 onLocationChanged 클래스를 구현해야합니까?
위치 업데이트를받지 않으려면 아니오입니다.
가장 간단한 방법은 무엇입니까?
가장 간단한 방법은 here과 같이 마지막으로 알려진 위치를 얻는 것입니다.
0
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) {
//...
}
});
관련 문제
- 1. 앱을 실행할 때 현재 위치 가져 오기
- 2. 현재 위치 업데이트 중 버튼을 클릭 할 수 없습니다.
- 3. 버튼을 클릭 할 때 이미지 가져 오기 및 표시
- 4. 버튼을 연속으로 클릭 할 때 ListView 항목 가져 오기
- 5. 테이블 행의 버튼을 클릭 할 때 모델 가져 오기
- 6. 버튼을 클릭 할 때 jQuery로 필드 가져 오기
- 7. Google지도 현재 위치 가져 오기
- 8. 앱을 여는 중 현재 위치 가져 오기
- 9. 클릭 할 때 링크 ID 가져 오기
- 10. JTextArea에서 클릭 할 때 줄 가져 오기
- 11. 안드로이드의 버튼을 클릭 할 때 오류가 발생했습니다.
- 12. 요소의 위치/위치 가져 오기
- 13. 현재 위치 가져 오기 (경도 및 위도)
- 14. 버튼을 클릭 할 때지도 위치 업데이트
- 15. Recyclerview BaseAdapter에서 클릭 한 위치 가져 오기
- 16. 현재 키 커서 위치 텍스트 가져 오기
- 17. 현재 GPS 위치 가져 오기. 전화
- 18. 사용자가 버튼을 클릭 할 때의 위치
- 19. 위치 요청시 현재 날짜 가져 오기
- 20. Google+ API : 프로필의 현재 위치 가져 오기
- 21. 코드 미러 현재 위치 가져 오기
- 22. 입력 목록에서 현재 위치 가져 오기
- 23. JSP에서 현재 위치 경로 가져 오기?
- 24. UIElement를 기준으로 클릭 마우스 위치 가져 오기
- 25. 페이지로드 버튼을 클릭 할 때
- 26. 현재 창 상단에서 위치 가져 오기
- 27. 비동기 작업을 사용하여 현재 위치 가져 오기
- 28. 보기 호출기에서 현재 항목 위치 가져 오기
- 29. 현재 위치 가져 오기 후지도 새로 고침
- 30. 현재 모니터에서 구성 요소 위치 가져 오기