0
여기 상황이 있습니다. 나는 경도와 위도가 1 떨어져있을 때만 나타나는 마커를 만들려고합니다. 또한 LatLngBounds를지도에서 처음부터 1 마디 내에 마커에 맞게 만들려고합니다.Google지도 마커 설정 및 경계 지정 - Android
나는 모든 것을 작동시킬 수는 있지만 동시에 할 수는 없습니다. If/Else 문에 잘못된 것이 있습니다.
protected void onPostExecute(Address address) {
mMap.clear();
if (address == null) {
Toast.makeText(MainActivity.this, R.string.invalid_entry, Toast.LENGTH_LONG).show();
} else {
String addressName = "";
for (int i = 0; i < address.getMaxAddressLineIndex(); i++) {
addressName += " - " + address.getAddressLine(i);
}
Double longitude = address.getLongitude();
Double latitude = address.getLatitude();
LatLng position = new LatLng(address.getLatitude(), address.getLongitude());
LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(position);
builder.include(position);
//search location
mMap.addMarker(new MarkerOptions().position(position).title(addressName)
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)));
for (int i = 0; i < markers.size(); i++) {
Double distanceLng = Math.abs(markers.get(i).longitude - longitude);
Double distanceLat = Math.abs(markers.get(i).latitude - latitude);
if ((distanceLng < 1) && (distanceLat < 1)) {
mMap.addMarker(new MarkerOptions()
.position(markers.get(i))
.title("Place")
.snippet("Description"));
builder.include(markers.get(i));
LatLngBounds bounds = builder.build();
int padding = 50; // offset from edges of the map in pixels
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
Log.d(TAG, "DistanceBounds: " + bounds);
Log.d(TAG, "DistancePadding: " + padding);
Log.d(TAG, "DistanceI: " + i);
mMap.moveCamera(cu);
}
else {
Toast.makeText(MainActivity.this, R.string.no_places_in_area,Toast.LENGTH_LONG);
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(position, 10));
Log.d(TAG, "DistanceLng Failed = " + distanceLng + "i = " + i);
Log.d(TAG, "DistanceLat Failed = " + distanceLat + "i = " + i);
}
}
}
올바른 코드 작성에 도움을 주시면 감사하겠습니다!
Whare는 builder.include (position);을 두 번 입력했는데 두 번째는 대개 오타입니다 –
또한 '1 경도와 위도가 어둡습니다'라고 말한 경우 distanceLng에서 distanceLng을 빼야합니다. –