android studio中google maps api的问题(problems with google maps api in android studio)

编程入门 行业动态 更新时间:2024-10-27 04:25:22
android studio中google maps api的问题(problems with google maps api in android studio)

我已经编写了代码,在我的一个片段(标签)中有谷歌地图,我似乎有一个问题与地图读回调,它说它未使用的导入语句。 我的所有图书馆都已经编译过,我已经同步了gradle,它仍然无法正常工作,我仍然是android的新手,所以这不是我最强的领域。

这是我的代码如下

package com.example.hp_user.shoutfinal28; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import com.google.android.gms.maps.MapFragment; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.OnMapReadyCallback; public class FragmentShouts_Maps extends Fragment implements onMapReadyCallback { View view = inflater.inflate(R.layout.fragmentshouts_maps, container, false); public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Get the view from fragment shouts.xml return inflater.inflate(R.layout.fragmentshouts_maps, container, false); MapFragment fragment = (MapFragment)getChildFragmentManager().findFragmentById(R.id.maps); fragment.getMapAsync(this); } @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); } @Override public void onMapReady (GoogleMap googleMap) }

这是我声明地图的xml文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <fragment android:id="@+id/maps" android:layout_width="match_parent" android:layout_height="match_parent" class="com.example.hp_user.shoutfinal28.FragmentShouts_Maps" android:layout_alignParentEnd="true"> </fragment> </RelativeLayout>

i have written the code to have google maps in one of my fragments(tabs) and i seem to be having a problem with the on map read call back, its saying its unused import statement. all my libraries have been compiled, i have synced the gradle and it still wont work, i'm still new to android so this isn't my strongest area.

here is my code below

package com.example.hp_user.shoutfinal28; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import com.google.android.gms.maps.MapFragment; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.OnMapReadyCallback; public class FragmentShouts_Maps extends Fragment implements onMapReadyCallback { View view = inflater.inflate(R.layout.fragmentshouts_maps, container, false); public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Get the view from fragment shouts.xml return inflater.inflate(R.layout.fragmentshouts_maps, container, false); MapFragment fragment = (MapFragment)getChildFragmentManager().findFragmentById(R.id.maps); fragment.getMapAsync(this); } @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); } @Override public void onMapReady (GoogleMap googleMap) }

here is the xml file where i declare maps

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <fragment android:id="@+id/maps" android:layout_width="match_parent" android:layout_height="match_parent" class="com.example.hp_user.shoutfinal28.FragmentShouts_Maps" android:layout_alignParentEnd="true"> </fragment> </RelativeLayout>

最满意答案

在线上

public class FragmentShouts_Maps extends Fragment implements onMapReadyCallback {

onMapReadyCallback的第一个字母应该大写:OnMapReadyCallback

PS:与您提到的错误无关,但您还必须携带该行

View view = inflater.inflate(R.layout.fragmentshouts_maps, container, false);

到onCreateView方法的内部。

On the line

public class FragmentShouts_Maps extends Fragment implements onMapReadyCallback {

the first letter of onMapReadyCallback should be capitalised: OnMapReadyCallback

PS: Not related to the error you mentioned, but you also have to carry the line

View view = inflater.inflate(R.layout.fragmentshouts_maps, container, false);

to the inside of the onCreateView method.

更多推荐

android,maps,com,import,view,电脑培训,计算机培训,IT培训"/> <meta name="

本文发布于:2023-07-05 02:44:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1032115.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:google   studio   android   problems   api

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!