简体   繁体   English

Java Android谷歌地图改变缩放控制位置并将相机设置为标记

[英]Java Android Google maps change zoom controls position and set camera to marker

I want the zoom controls to be on the very top in the middle, I tried to do something like this but it does not work: 我希望缩放控件位于中间的顶部,我尝试做这样的事情,但它不起作用:

  SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().
                findFragmentById(R.id.map);
        View mapView = mapFragment.getView();
View zoom_in_button = mapView.findViewWithTag("GoogleMapZoomInButton");


RelativeLayout.LayoutParams location_layout = (RelativeLayout.LayoutParams) zoom_in_button.getLayoutParams();
        location_layout.addRule(RelativeLayout.CENTER_HORIZONTAL, 0);

Also I need to get this: center the view so that the marker is in the bottom left corner 此外,我需要得到这个:使视图居中,使标记位于左下角

I did this but it does not work. 我做了这个,但它不起作用。

mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(currentPGO.getLatitude(), currentPGO.getLongitude()), 16));

as far as I know, you cant change the Map controls you can just hide them and make your own zoom in and out buttons. 据我所知,您无法更改地图控件,您可以隐藏它们并制作自己的放大和缩小按钮。

map.getUiSettings().setZoomControlsEnabled(false);

and then make your buttons in a relative layout or constraints layout and position them as you wish. 然后在相对布局或约束布局中创建按钮,并根据需要定位它们。

and then to make them zoom in and out 然后让它们放大和缩小

(Snippet from google maps api for Android) https://developers.google.com/maps/documentation/android-sdk/views (来自谷歌地图api for Android的代码段) https://developers.google.com/maps/documentation/android-sdk/views

CameraUpdateFactory.zoomIn() and CameraUpdateFactory.zoomOut()// give you a CameraUpdate that changes the zoom level by 1.0, while keeping all other properties the same.
  1. Hide default zoom buttons of Google Maps 隐藏Google地图的默认缩放按钮

    mMap.uiSettings.isZoomControlsEnabled = false mMap.uiSettings.isZoomControlsEnabled = false

  2. Create ImageView/Button widget for Zoom In and Zoom Out (Align this on Top Center or wherever you prefer, above the fragment) 创建用于放大和缩小的ImageView / Button小部件(将其对齐在顶部中心或您喜欢的任何位置,在片段上方)

  3. Call the below methods on Widget click: 在Widget上调用以下方法单击:

    Zoom In 放大

    mMap.animateCamera(CameraUpdateFactory.zoomIn()) mMap.animateCamera(CameraUpdateFactory.zoomIn())

    Zoom Out 缩小

    mMap.animateCamera(CameraUpdateFactory.zoomOut()) mMap.animateCamera(CameraUpdateFactory.zoomOut())

Edit: If you wish to place the marker on Lower Left corner, you will need to calculate new LatLang value which would be slightly to the right and top of desired location and move the camera accordingly. 编辑:如果您希望将标记放在左下角,则需要计算新的LatLang值,该值略微位于所需位置的右侧和顶部,并相应地移动摄像机。 For example if your zoom level is 16, then use something like this: 例如,如果缩放级别为16,则使用以下内容:

var lat = markerLatLng.latitude
var lng = markerLatLng.longitude
mMap.addMarker(MarkerOptions().position(LatLng(lat, lng)))
lat += 0.005
lng += 0.003
moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(lat, lng), 16f))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM