【问题标题】:On Android, is it possible to send an intent to the Google maps application with a custom marker image specified in the intent?在 Android 上,是否可以使用意图中指定的自定义标记图像向 Google 地图应用程序发送意图?
【发布时间】:2012-12-05 12:08:15
【问题描述】:

默认的 Google 地图标记是红色大头针。是否可以通过意图将默认​​标记图像替换为自定义图像?

编辑: 这是在发送 geouri 意图以启动外部地图应用程序时。在带有 MapActivity 子类的应用程序中执行此操作时不会。

【问题讨论】:

  • 感谢您的回答。我忘了澄清我是在询问是否向外部地图应用程序发送意图。问题已编辑。

标签: android google-maps android-intent google-maps-markers


【解决方案1】:

您可以发送一个带有数组中图像位置的整数:

Intent i = new Intent (yourClass.this, MapActivity.class)
i.putExtra("pinPosition",2);
startActivity(i);

在您的地图活动中:

 public class MyMapActivity extends MapActivity {
    private int drawables[] = { R.drawable.pin1, R.drawable.pin2, R.drawable.tutorial_pin3 };
    int position;

    public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            if (getIntent().getSerializableExtra("pinPosition")!=null) {
        position = getIntent().getSerializableExtra("pinPosition");
            }

            setContentView(R.layout.publish_map_activity);
            map = (MapView) findViewById(R.id.mapview);
            ImageView pin = (ImageView) findViewById(R.id.drag);
            pin.setImageResource(drawables[position]);
    ....

    }

    }

如果你使用类似的google代码,你的xml应该是:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mapLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <com.google.android.maps.MapView
        android:id="@+id/mapview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:apiKey="@string/googlemaps_key"
        android:clickable="true" />

    <ImageView
        android:id="@+id/drag"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/contentDescription"
        android:src="@drawable/mapitempng"
        android:visibility="gone" />
</RelativeLayout>

【讨论】:

  • 感谢您的快速回答!我忘了说明我是在询问是否向外部地图应用程序发送意图。但我希望这可以帮助任何尝试在其应用程序中的地图视图上使用自定义图像标记的人。
【解决方案2】:

是的。我只是希望我能正确地回答你的问题: 您可以通过叠加项目来做到这一点。只需查看 Google 本身的 THIS 示例: 您可以通过指定可绘制对象来自定义任何标记。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多