Google지도 API v2의 기본 위치 및 확대 / 축소 수준을 어떻게 설정합니까?
내지도가 표시되면 항상 고정 된 위치 (아프리카 근처)에서 시작합니다.
그런 다음 다음 코드를 사용하여 원하는 위치에지도를 중앙에 배치합니다.
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(loc.getLatitude(), loc.getLongitude()), 14.0f));
내 질문은지도가 표시되기 전에 기본 위치와 확대 / 축소 수준을 설정할 수 있다는 것입니다.
사용자가 처음에 애니메이션을 보는 것을 원하지 않기 때문입니다.
감사.
이것을 사용하여 애니메이션없이 직접 확대 / 축소 할 수 있습니다.
map.moveCamera( CameraUpdateFactory.newLatLngZoom(new LatLng(xxxx,xxxx) , 14.0f) );
여기에서 문서를 살펴보십시오.
https://developers.google.com/maps/documentation/android-api/map#configure_initial_state
이를 수행하는 방법은지도를 XML을 통해 추가하는지 프로그래밍 방식으로 추가하는지에 따라 약간 다릅니다. XML을 사용하는 경우 다음과 같이 할 수 있습니다.
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"
map:cameraBearing="112.5"
map:cameraTargetLat="-33.796923"
map:cameraTargetLng="150.922433"
map:cameraTilt="30"
map:cameraZoom="13"/>
프로그래밍 방식으로 수행하는 경우 다음을 수행 할 수 있습니다.
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(-33, 150))
.zoom(13)
.build();
MapFragment.newInstance(new GoogleMapOptions()
.camera(camera));
프로그래밍 방식으로 Google Map
초기 에로드하려는 Location
경우이 코드를 사용할 수 있습니다.
FragmentManager fm = getFragmentManager(); // getChildFragmentManager inside fragments.
CameraPosition cp = new CameraPosition.Builder()
.target(initialLatLng) // your initial co-ordinates here. like, LatLng initialLatLng
.zoom(zoom_level)
.build();
SupportMapFragment mapFragment = SupportMapFragment.newInstance(new GoogleMapOptions().camera(cp));
fm.beginTransaction().replace(R.id.rl_map, mapFragment).commit();
다음 코드를 추가하십시오. layout
<RelativeLayout
android:id="@+id/rl_map"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
이것은 GoogleMap
특히 Location
initialLatLng 에서 직접 로드 됩니다 .
나는 핸들을 생성 SupportMapFragment
하고 설정 visibility
에 View.INVISIBLE
사용 SupportMapFragment.getView().setVisibility()
. 그런 다음 onLocationChanged
내 클래스가 구현 하는 콜백 에서 true인지 확인 INVISIBLE
하고 설정 VISIBLE
합니다. 이것은 당신이 시작 위치를 동적으로 초기화 할 수있게하면서 당신이로드에서 보는 점프를 제거합니다. 제 경우에는 사용자 위치를 중심으로 카메라를 중앙에 배치 onLocationChanged
하므로 setMyLocationEnabled(true)
.
Your requirements may be different, but either way you just need to set the visibility to INVISIBLE
and then find a good place to set VISIBLE
after your appropriate data has been loaded.
you can use directy CameraUpdate using static latlong
LatLong latlong = new LatLong(lat, long);
CameraUpdate cameraPosition = CameraUpdateFactory.newLatLngZoom(latLong, 15);
mGoogleMap.moveCamera(cameraPosition);
mGoogleMap.animateCamera(cameraPosition);
'program story' 카테고리의 다른 글
문자열에서 부동 숫자를 추출하는 방법 (0) | 2020.09.15 |
---|---|
jQuery 날짜 선택기-과거 날짜 비활성화 (0) | 2020.09.15 |
Django 인기의 역사 (0) | 2020.09.15 |
PowerShell의 파일 이름에서 경로 및 확장자 제거 (0) | 2020.09.15 |
코드를 컴파일하지 않는 Android Studio 3.1 '실행' (0) | 2020.09.14 |