您的位置:首页 > 编程语言 > Go语言

google地图 MapFragment

2016-04-19 07:58 435 查看
MapView ,MapActivity 这种的局限在于,必须要继承MapActivity,否则无法使用MapView, MapFragment 这种的局限在于,必须要安装Google Play Service ,也就是说必须是原生rom。而且sdk要在12以上
打开sdk manager--在Extras里把Android Support Libaray 和 Google Play Services都安装,lib和samples都在sdk_path/extra/google/google_play_services下。导入../lib_project作为自己项目的libaray

这一步完了之后在manifest.xml文件里添加权限和api key。代码如下

<permission

android:name="com.example.permission.MAPS_RECEIVE"

android:protectionLevel="signature"/>

com.example替换成自己project的package

<uses-permission android:name="com.example.permission.MAPS_RECEIVE"/>

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

<uses-permission android:name="android.permission.INTERNET"/>

<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>

<!--My Location-->

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

<!--Maps API needs OpenGL ES2.0.-->

<uses-feature

android:glEsVersion="0x00020000"

android:required="true"/>

放在application声明里

<meta-data

android:name="com.google.android.maps.v2.API_KEY"

android:value="appkey"/>

在layout xml里加入MapFragment声明

<fragment xmlns:android="http://schemas.android.com/apk/res/android"

android:id="@+id/map"

android:layout_width="match_parent"

android:layout_height="match_parent"

class="com.google.android.gms.maps.MapFragment"/>

activity不变,extends Activity就可以了。 不需要继承MapActivity了。 

注意,debug状态下是不可以显示地图的,一定要在正式签名下map才会显示出来。

install下应该就能看到map了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: