使用MapView时如何从V1切换到Maps V2

时间:2016-12-03 18:16:54

标签: android google-maps android-fragments

之前,我们能够做到这样的事情:

package com.bignerdranch.android.taskmanager;
import android.os.Bundle;
import com.google.android.maps.MapActivity;

public class AddLocationMapActivity extends MapActivity {

    public static final String ADDRESS_RESULT = "address";

    @Override
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.add_location);
    }

    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }

    @Override
    protected boolean isLocationDisplayed() {
        return true;
    }
}

与布局类一起:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <TextView
        android:id="@+id/location_title"
        .../>

    <EditText
        android:id="@+id/task_address"
        .../>

    <Button
        android:id="@+id/map_location_button"
        .../>

    <com.google.android.maps.MapView
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/map_location_button"
        android:layout_above="@+id/use_this_location_button"
        android:clickable="true"
        android:apiKey="AIza..............................." />

    <Button
        android:id="@id/use_this_location_button"
        .../>

</RelativeLayout>

但是现在这不能用于V1键,所以我的问题是如何更改它以使其与V2键一起使用?我已经读过我应该使用片段,但我是Android编程的新手,所以我不知道如何编写它,仍然使我的应用程序按预期工作。

谢谢!

1 个答案:

答案 0 :(得分:0)

  

但是现在这不能用于V1键,所以我的问题是如何更改它以使其与V2键配合使用?

丢弃所有代码并使用the Maps V2 SDK。 Maps V1无法使用Maps V2键。

  

这应该显示一个你可以四处移动的地图,但由于不推荐使用V1键,它不再有效。

地图V1已被弃用了相当长的一段时间。你甚至可以获取 Maps V1密钥已经将近4年了,而之前的地图V1被认为已被弃用了一段时间。