메신저를 Google지도에로드하는 중입니다.지도 및 40 개의 마커를로드하는 데 약 5 초가 걸립니다. (지도 및 마커가로드되기 전에 화면이 비어 있음)Google지도 표시자를 더 빠르게로드하는 방법은 무엇입니까?
다음은 내 xml 파일입니다.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>
다음 코드는지도에 마커를 추가 :
1), 모든 레스토랑 객체를 반복 각 레스토랑에 대한 주소를 가져옵니다.
2) LatLng를에 주소가
3) 마커를 추가하는 방법 AsyncTask
의 onPostExecute
를 사용
//partial of the method
for (Restaurant rest : rests) {
LatLng ll = getLatLng(rest.getAddress());//converts address to LatLng
MarkerOptions marker = new MarkerOptions()
.title(rest.getName())
// .snippet("Briefly description: " + i++)
.position(ll)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker))
.anchor(0.0f, 1.0f);
myMap.addMarker(marker);
}
public LatLng getLatLng(String address) {
try {
ArrayList<Address> addresses = (ArrayList<Address>) geocoder.getFromLocationName(address, MAX_ADDRESS_ALLOWDED);
for (Address add : addresses) {
if (true) {//Controls to ensure it is right address such as country etc.
longitude = add.getLongitude();
latitude = add.getLatitude();
}
}
} catch (Exception e) {
Toast.makeText(myContext, e.getMessage(), Toast.LENGTH_SHORT).show();
}
return new LatLng(latitude, longitude);
}
임 마커에 추가 개체를 변환, 누구든지 나를 도울 수 있습니까?
매번로드하지 못하도록 위 주소를 찾아 본 후 위도와 경도를 캐싱하도록 제안합니다. 지오 코더 요청이 차단되어 오랜 시간이 걸릴 수 있습니다. – kcoppock