Google지도를 내가 작업하고있는 앱에 통합하기 위해 노력하고 있습니다. 지금까지 오히려 불쾌한 시간이었습니다. 그럼에도 불구하고 마침내지도를 표시하고 위치 및 확대/축소 수준을 설정하는 SupportMapFragment를 얻었습니다. 여기 Google지도 안드로이드 - 갑자기 더 이상 표시되지 않는지도
는 지금까지 내 코드의 기능 비트 :@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Location location = BundleChecker.getExtraOrThrow(KEY_LOCATION, new Bundle[] { savedInstanceState, getArguments() });
setLocation(location);
if (checkGooglePlayServicesStatus() == ConnectionResult.SUCCESS) {
setMapFragment(new SupportMapFragment());
getActivity().getSupportFragmentManager().beginTransaction().add(R.id.location_detail_mapFrame, getMapFragment()).commit();
}
populateAddress();
attachButtonListeners();
Runnable initMap = new Runnable() {
@Override
public void run() {
if (checkGooglePlayServicesStatus() == ConnectionResult.SUCCESS) {
try {
GoogleMap map = getMapFragment().getMap();
LatLng latLng = getLocation().getAddress().getLatLng(getActivity());
CameraUpdate update = CameraUpdateFactory.newLatLngZoom(latLng, DEFAULT_MAP_ZOOM);
map.animateCamera(update);
}
catch (IOException e) {
Log.e(TAG, e.getMessage(), e);
Toast.makeText(getActivity(), "Unable to find location", Toast.LENGTH_SHORT).show();
}
}
}
};
Handler handler = new Handler();
handler.postDelayed(initMap, 200);
}
또한, 나는 당신이뿐만 아니라 비판 할 수 있습니다 내 주소 모델에서 위도 경도를 얻을 수있는 간단한 편리한 방법을 썼다 :
/*
* Convenience method to easily check if there is a valid lat & lng in this address
*/
public boolean hasLatLng() {
return getLatitude() != null && getLongitude() != null;
}
/*
* Convenience method for use with Google Maps API
*/
public LatLng getLatLng(Context context) throws IOException {
LatLng latLng = null;
if (hasLatLng()) {
latLng = new LatLng(getLatitude(), getLongitude());
}
else {
String locationString = getStreet() + ", " + AddressUtil.makeCityStateZipString(this);
Geocoder geoCoder = new Geocoder(context);
try {
List<android.location.Address> matches = geoCoder.getFromLocationName(locationString, 2);
if (matches != null && matches.size() > 0) {
double lat = matches.get(0).getLatitude();
double lng = matches.get(0).getLongitude();
latLng = new LatLng(lat, lng);
}
}
catch (IOException e) {
throw new IOException(e);
}
}
return latLng;
}
을
이 코드는 이상적이지 않으며 리팩토링해야한다는 점을 알고 있습니다. 이번이 처음 Google지도 작업을하는 것이므로 어떻게 할 수 있을지 제안 해주십시오. 내 레이아웃 XML에서 MapFragment를 사용하려고 할 때 많은 문제를 겪었으므로 프로그래밍 방식으로 만듭니다.
문제의 핵심 : 스테이징 서버에서 일부 가짜 주소 데이터를 얻었으므로 AddressUn getLatLng 메서드가 null을 반환하여 CameraUpdateFactory.newLatLngZoom을 호출 할 때 예외가 발생했습니다. 이 예외가 발생하면 Google에서 더 이상지도 데이터를 가져올 수 없습니다. 지도 조각은 지금 비어와 메시지가 로그 캣에 표시됩니다
05-21 18 : 11 : 42.903 : I/Google지도 안드로이드 API (15747) : 구글 서버에 연결하지 못했습니다. 연결이 설정되면 다른 시도가 수행됩니다.
05-21 18 : 11 : 43.093 : E/Google지도 Android API (15747) :지도를로드하지 못했습니다. Google 서버에 접속하는 중에 오류가 발생했습니다. 아마도 인증 문제 일 수 있습니다 (네트워크 오류로 인한 것일 수 있음).
새로운 api 키를 만들고 내 매니페스트의 현재 키를 변경하지 않았습니다. 위 코드에 대한 유일한 변경 사항은 null LatLng을 설명하는 것이 었습니다. 그런 다음 변경 사항을 실행 취소하여 코드를 기능 상태로 되돌려 놓았습니다.
또한 약간 낯선 것을 만들기 위해 Google Play 서비스 추가 프로그램에 포함 된 샘플지도 프로젝트를 작성했으며 완벽하게 작동합니다 (별도의 API 키, btw 사용).
내가 여기 잘못했을 수 있습니까? 나는 명백한 것을 간과하고 있는가?
https://developers.google.com/maps/documentation/android/ – kongkea
어떤 버전의 Google지도를 사용하고 있습니까? 또한 맵에 디버깅 키 또는 릴리스 키를 사용하고 있습니까? – MiStr
@kongkea 당신이 당신의 링크를 쓸 의도가 있습니까? 지도 개발자 문서에 대한 링크를 게시하고 아무 것도 말하지 않는 것은 쓸모가 없습니다. – dm78