gpt4 book ai didi

android - 谷歌地图 :onMapReadyCallback can not be applied to this activity

转载 作者:行者123 更新时间:2023-11-29 15:44:11 25 4
gpt4 key购买 nike

我是一个尝试使用谷歌地图的初学者,我已经按照这里给出的说明进行操作:https://developers.google.com/maps/documentation/android-api/map?hl=zh-tw

但我被困在 mapFragment.getMapAsync(this) 并且无法找到答案。

代码如下:

public class GoogleMapPage extends FragmentActivity   {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.googlemap);
MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this)<---it said "onMapReadyCallback can not be applied to this activity;
}

}

这是 XML:

     <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal">


<fragment
android:layout_width="300dp"
android:layout_height="300dp"
android:name="com.google.android.gms.maps.MapFragment"
android:id="@+id/map"
tools:layout="@layout/googlemap" />

最佳答案

您需要让您的 Activity 实现 OnMapReadyCallback 并覆盖方法 void onMapReady(GoogleMap googleMap)

public class GoogleMapPage extends FragmentActivity implements OnMapReadyCallback   {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.googlemap);
MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this) // <---it said "onMapReadyCallback can not be applied to this activity;
}


@Override
public void onMapReady(GoogleMap googleMap) {
// Do stuff with the map here!
}

}

关于android - 谷歌地图 :onMapReadyCallback can not be applied to this activity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35340848/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com