添加标记到谷歌地图片段 [英] Adding a marker to a Google maps fragment

查看:171
本文介绍了添加标记到谷歌地图片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加了一个地图片段到我的应用程序,并增加了以下code放置一个标记上fragment.But我得到的错误在code snippet.I已包括所有相关的进口。

I have added a map fragment to my application and added the following code to place a marker on the fragment.But I'm getting errors in the code snippet.I have included all relevant imports.

的错误被编译时和如下:

The errors are compile time and are as follows:

1.MapFragment不能被解析为一个类型。

1.MapFragment cannot be resolved to a type.

2.GoogleMap不能被解析为一个类型。

2.GoogleMap cannot be resolved to a type.

3.LatLng不能被解析为一个类型。

3.LatLng cannot be resolved to a type.

mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
        mMap.addMarker(new MarkerOptions()
                .position(new LatLng(0, 0))
                .title("Hello world"));

任何人有任何想法,其中的错误是在片段?谢谢

Anyone have any ideas where the error is in the snippet? Thanks

推荐答案

我觉得你应该先检查两件事情

I think you should check two things first


  1. 是谷歌Play业务项目或库添加到您的项目?如果没有,检查该链接 http://developer.android.com/google/play -Services / setup.html

  2. 如果您编译Android版本和LT; 11,你需要使用supportFragmentManager而不是通常的FragmentManager的:

  1. Is the Google Play Service project or library added to your project ? If not, check this link http://developer.android.com/google/play-services/setup.html
  2. If you compile for android version < 11, you need to use supportFragmentManager instead of the normal FragmentManager :

         mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();


在最后一种情况下,你还需要在你的XML使用该类更新到类=com.google.android.gms.maps.SupportMapFragment

In the last case, you also need to update the class used in your XML to class="com.google.android.gms.maps.SupportMapFragment"

这篇关于添加标记到谷歌地图片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆