Android 将 ImageView 放在地图的赤道上

Posted

技术标签:

【中文标题】Android 将 ImageView 放在地图的赤道上【英文标题】:Android place ImageView on the equator of map 【发布时间】:2017-02-28 17:03:48 【问题描述】:

我有一张地图,我想在其上放置 ImageView,使其尖端接触赤道。我将属性 centerVertical=true 和 centerHorizo​​ntal=true 赋予 ImageView,但它没有定位在赤道上。我得到了中心地图,但我希望 ImageView 位于地图的赤道上。

截图:

代码:

@Override
    public void onMapReady(GoogleMap googleMap) 
        this.googleMap = googleMap;
        googleMap.getUiSettings().setZoomControlsEnabled(true);
        googleMap.getUiSettings().setCompassEnabled(true);
        //center of map
        LatLng centerOfMap=this.googleMap.getCameraPosition().target;

marker_view.xml:

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_
    android:layout_ >
    <ImageView
        android:id="@+id/marker_icon_view"
        android:layout_
        android:layout_
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="162dp"
        android:contentDescription="@string/app_name"
        android:src="@drawable/marker" />
</RelativeLayout>

【问题讨论】:

【参考方案1】:

您应该使用标记。您也可以自定义它们。请查看 Google 和 SO 提供的以下文档。

https://developers.google.com/maps/documentation/android-api/marker

How to create a custom-shaped bitmap marker with Android map API v2

【讨论】:

我希望即使用户移动地图也能看到标记 使用 Projection 类我得到了赤道 LatLng(0.0,0.0) 的屏幕位置,但它显示 x 和 y 值为 0。 只需为您的drawable/marker 设置双倍高度,其中心应位于底部。并查看this 对话。

以上是关于Android 将 ImageView 放在地图的赤道上的主要内容,如果未能解决你的问题,请参考以下文章

如何将ImageView放在Xamarin.Android应用程序中,根据设备屏幕大小自行调整大小?

如何在 android imageview 上显示静态谷歌地图?

Android - 将 ImageView 保存到具有全分辨率图像的文件

Android:将元素放在另一个元素下方并在屏幕底部对齐

ImageView

在放大和缩小时在imageview上移动对象