【问题标题】:How do I show a map legend on an Android Google Map?如何在 Android 谷歌地图上显示地图图例?
【发布时间】:2011-04-25 19:35:20
【问题描述】:

谷歌地图的网络版允许开发者显示一个地图图例,表明地图的比例。

有没有办法使用 Android API 来做到这一点?

附加信息:

  • 我想以图形方式显示“此距离等于 X 米”,就像您访问 google 地图时那样。
  • 应该可以使用:getProjection(),但我只是希望有一种方法可以启用图例。
  • 如果您打开 Google 地图应用并选择“实验室”,您可以启用我想要的“比例尺”。

【问题讨论】:

  • 我认为您将不得不按照您的说法使用 getProjection。在屏幕的左侧和右侧找到 GeoPoints,计算它们之间的公里数,选择合适的 1km/10km(取决于缩放)等线在画布上绘制并绘制一些文本并将其添加为叠加层。也许添加一些细分刻度线。相当乏味,但完成后应该看起来不错!

标签: android google-maps


【解决方案1】:

看看他们对用于 OpenStreetMap 的非常相似的 Osmdroid 做了什么

ScaleBarOverlay

它应该提供一些想法。它可能比您需要的功能更全面。

【讨论】:

    【解决方案2】:

    使用文本视图创建一个布局,将其加载到您的 onCreate 中,然后使用 setText() 将地图比例写入其中。下面是一个示例布局:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent" android:id="@+id/root">
            <com.google.android.maps.MapView
                     android:layout_width="fill_parent"
                     android:layout_height="fill_parent"
                     android:enabled="true"
                                     android:clickable="true"
                                     android:id="@+id/map"
                     android:apiKey="<YOUR KEY>"
                     android:layout_alignParentTop="true" android:layout_alignParentRight="true" android:layout_alignParentL
    eft="true" android:layout_alignParentBottom="true"/>
                    <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:layout_marginLeft="10sp" android:layout_marginRight="10sp" android:layout_marginTop="10sp" android:id="@+id/scale" android:gravity="center_horizontal"></TextView>
    </RelativeLayout>
    

    在你的活动中,你可以做

    ((TextView)findViewById(R.id.scale)).setText("<map scale>");
    

    它应该出现在地图的顶部。您也可以根据需要设置文本视图的样式。

    【讨论】:

    • 这不能回答我的问题。查看问题了解更多信息
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-01
    • 1970-01-01
    • 2014-08-05
    • 1970-01-01
    • 2015-05-11
    • 1970-01-01
    相关资源
    最近更新 更多