Как изменить положение или удалить значок GPS по умолчанию на картах Google?
Я новичок в Google Maps и его apis. Здесь я загрузил Google Map и пытаюсь изменить положение этого значка GPS на прикрепленном изображении, но он не перемещается из своего положения.
Я загрузил карту с помощью SupportMapFragment и использовал метод getMapAsync для получения объекта карты в методе onMapReady(). Я знаю, если я удалю getMapAsync, этот значок будет удален, но без него я не смогу получить объект карты. Так что это проблема я сталкиваюсь.
Есть ли что-нибудь, чтобы переместить его положение или убрать? Помощь будет оценена. Спасибо.
2 ответа
Решение
Удалять Location Button
в onMapReady добавить
map = googleMap;
map.getUiSettings().setMyLocationButtonEnabled(false);
Вы можете изменить это, получив вид этой кнопки текущего местоположения из фрагмента
//Fragment code to change the position of the current location button
private SupportMapFragment mapFragment;
mapFragment = (SupportMapFragment) this.getChildFragmentManager()
.findFragmentById(R.id.map);
@Override
public void onMapReady(GoogleMap googleMap) {
try {
map = googleMap;
if (mapFragment != null &&
mapFragment.getView().findViewById(Integer.parseInt("1")) != null) {
// Get the button view
View locationButton = ((View) mapFragment.getView().findViewById(Integer.parseInt("1")).getParent()).findViewById(Integer.parseInt("2"));
// and next place it, on bottom right (as Google Maps app)
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams)
locationButton.getLayoutParams();
// position on right bottom
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, 0);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, 0);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_START, 0);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_END, RelativeLayout.TRUE);
layoutParams.addRule(RelativeLayout.CENTER_VERTICAL, 0);
int marginBottom = mNavigationListFragment.llTypeContainer.getHeight() + 5;
int marginRight = (int)convertFromDpToPixel(context, 10);
layoutParams.setMargins(0, 0, marginRight, marginBottom);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static final float convertFromDpToPixel(Context context, float dp) {
float ht_px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, context.getResources().getDisplayMetrics());
return ht_px;
}
Чтобы скрыть эту кнопку используйте код ниже:
@Override
public void onMapReady(GoogleMap googleMap) {
map = googleMap;
map.getUiSettings().setMyLocationButtonEnabled(false);
}