移动应用地图工具包WhirlyGlobe-Maply新建android项目
2016-08-03 14:09
573 查看
WhirlyGlobe-Maply是一个基于OpenGL ES、专注移动应用的开源地图工具包,支持ios和android平台,本文以android平台为例。
环境:windows7 64位,Androidstudio 1.2.2,WhirlyGlobe-Maply(下载地址)
打开Androidstudio,新建一个名为“HelloEarth”的项目:
选择SDK
选择空的activity
保持默认名称MainActivity,也可以修改名称
点击Finish完成。
复制WhirlyGlobeMaply.aar(下载压缩包app/libs/WhirlyGlobeMaply.aar)到app/libs文件夹下:
打开build.gradle(Project:HelloEarth)文件,在allprojects里面添加如下内容:
打开build.gradle(Module:app)文件,在dependencies里面添加以下内容:
右键点击MainActivity,在项目窗口中选择一个新的空白的Fragment,命名为HelloGlobeFragment,去掉三个对勾
打开activity_main.xml,注释掉原有的HelloWorld文本框,改为以下内容
打开HelloGlobeFragment.java,修改原有的代码为以下代码
成果如图,可以通过双击放大:
以上是创建球状地图,接下来我们创建二维地图:
如上述过程选择一个新的空白的Fragment,命名为HelloMapFragment,修改activity_main.xml内容
修改HelloMapFragment.java代码
成果如图,同样双击放大:
完成!
环境:windows7 64位,Androidstudio 1.2.2,WhirlyGlobe-Maply(下载地址)
打开Androidstudio,新建一个名为“HelloEarth”的项目:
选择SDK
选择空的activity
保持默认名称MainActivity,也可以修改名称
点击Finish完成。
复制WhirlyGlobeMaply.aar(下载压缩包app/libs/WhirlyGlobeMaply.aar)到app/libs文件夹下:
打开build.gradle(Project:HelloEarth)文件,在allprojects里面添加如下内容:
打开build.gradle(Module:app)文件,在dependencies里面添加以下内容:
右键点击MainActivity,在项目窗口中选择一个新的空白的Fragment,命名为HelloGlobeFragment,去掉三个对勾
打开activity_main.xml,注释掉原有的HelloWorld文本框,改为以下内容
<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" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> <!--<TextView android:text="@string/hello_world" android:layout_width="wrap_content"--> <!--android:layout_height="wrap_content" />--> <fragment android:layout_width="fill_parent" android:layout_height="fill_parent" android:name="com.example.administrator.helloearth.HelloGlobeFragment" android:id="@+id/fragment" android:layout_centerVertical="true" android:layout_centerHorizontal="true"></fragment> </RelativeLayout>
打开HelloGlobeFragment.java,修改原有的代码为以下代码
package com.example.administrator.helloearth; import android.os.Bundle; import android.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import com.mousebird.maply.GlobeMapFragment; import com.mousebird.maply.QuadImageTileLayer; import com.mousebird.maply.RemoteTileInfo; import com.mousebird.maply.RemoteTileSource; import com.mousebird.maply.SphericalMercatorCoordSystem; import java.io.File; /** * A simple {@link Fragment} subclass. */ public class HelloGlobeFragment extends GlobeMapFragment { // public HelloGlobeFragment() { // // Required empty public constructor // } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle inState) { // TextView textView = new TextView(getActivity()); // textView.setText(R.string.hello_blank_fragment); // return textView; super.onCreateView(inflater,container,inState); return baseControl.getContentView(); } @Override protected MapDisplayType chooseDisplayType(){ return MapDisplayType.Globe; } @Override protected void controlHasStarted(){ // 设置瓦片地图 String cacheDirName="stamen_watercolor"; File cacheDir=new File(getActivity().getCacheDir(),cacheDirName); cacheDir.mkdir(); RemoteTileSource remoteTileSource=new RemoteTileSource(new RemoteTileInfo("http://tile.stamen.com/watercolor/","png",0,18)); remoteTileSource.setCacheDir(cacheDir); SphericalMercatorCoordSystem coordSystem=new SphericalMercatorCoordSystem(); // 当为全球显示时使用globeControl // 当为地图显示时使用mapControl QuadImageTileLayer baseLayer=new QuadImageTileLayer(globeControl,coordSystem,remoteTileSource); baseLayer.setImageDepth(1); baseLayer.setSingleLevelLoading(false); baseLayer.setUseTargetZoomLevel(false); baseLayer.setCoverPoles(true); baseLayer.setHandleEdges(true); // 添加图层并确定位置 globeControl.addLayer(baseLayer); globeControl.animatePositionGeo(-3.6704803, 40.5023056, 5, 1.0); } }
成果如图,可以通过双击放大:
以上是创建球状地图,接下来我们创建二维地图:
如上述过程选择一个新的空白的Fragment,命名为HelloMapFragment,修改activity_main.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" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> <!--<TextView android:text="@string/hello_world" android:layout_width="wrap_content"--> <!--android:layout_height="wrap_content" />--> <!--<fragment--> <!--android:layout_width="fill_parent"--> <!--android:layout_height="fill_parent"--> <!--android:name="com.example.administrator.helloearth.HelloGlobeFragment"--> <!--android:id="@+id/fragment"--> <!--android:layout_centerVertical="true"--> <!--android:layout_centerHorizontal="true"></fragment>--> <fragment android:layout_width="fill_parent" android:layout_height="fill_parent" android:name="com.example.administrator.helloearth.HelloMapFragment" android:id="@+id/fragment" android:layout_centerVertical="true" android:layout_centerHorizontal="true"></fragment> </RelativeLayout>
修改HelloMapFragment.java代码
package com.example.administrator.helloearth; import android.os.Bundle; import android.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import com.mousebird.maply.GlobeMapFragment; import com.mousebird.maply.QuadImageTileLayer; import com.mousebird.maply.RemoteTileInfo; import com.mousebird.maply.RemoteTileSource; import com.mousebird.maply.SphericalMercatorCoordSystem; import java.io.File; /** * A simple {@link Fragment} subclass. */ public class HelloMapFragment extends GlobeMapFragment { // public HelloGlobeFragment() { // // Required empty public constructor // } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle inState) { // TextView textView = new TextView(getActivity()); // textView.setText(R.string.hello_blank_fragment); // return textView; super.onCreateView(inflater,container,inState); return baseControl.getContentView(); } @Override protected MapDisplayType chooseDisplayType(){ return MapDisplayType.Map; } @Override protected void controlHasStarted(){ // 设置瓦片地图 String cacheDirName="stamen_watercolor"; File cacheDir=new File(getActivity().getCacheDir(),cacheDirName); cacheDir.mkdir(); RemoteTileSource remoteTileSource=new RemoteTileSource(new RemoteTileInfo("http://tile.stamen.com/watercolor/","png",0,18)); remoteTileSource.setCacheDir(cacheDir); SphericalMercatorCoordSystem coordSystem=new SphericalMercatorCoordSystem(); // 当为全球显示时使用globeControl // 当为地图显示时使用mapControl QuadImageTileLayer baseLayer=new QuadImageTileLayer(mapControl,coordSystem,remoteTileSource); baseLayer.setImageDepth(1); baseLayer.setSingleLevelLoading(false); baseLayer.setUseTargetZoomLevel(false); baseLayer.setCoverPoles(true); baseLayer.setHandleEdges(true); // 添加图层并确定位置 mapControl.addLayer(baseLayer); mapControl.animatePositionGeo(103.994067, 30.770697, 5, 1.0); mapControl.setAllowRotateGesture(true); } }
成果如图,同样双击放大:
完成!
相关文章推荐
- 基于Android移动终端的搜索客户端应用【团队项目】
- 人机交互实验:Android开发之人物移动、地图滑动、传感器、触屏的应用
- Android应用开发实战-移动终端团购网项目开发(送源代码)
- Android应用开发学习总结(二)——新建项目与目录结构了解
- 移动开发----android Intent调用地图应用客户端
- 集成 移动地图选址、Fresco的应用、卓越wifi、刮刮卡、抽屉式菜单 的一个项目
- Android开发者必须深入学习的10个应用开源项目
- Android开发者应该深入学习的10个开源应用项目【ZZ】
- Android开发者必须深入学习的10个应用开源项目
- Android开发者必须深入学习的10个应用开源项目
- Android开发者应该深入学习的10个开源应用项目(转)
- Android开发者应该深入学习的10个开源应用项目_IT新闻_博客园
- Android开发者必须深入学习的10个应用开源项目
- 新建android项目的结构
- 10个经典的Android开源应用项目
- Android开发者应该深入学习的10个开源应用项目[转]
- 10个经典的Android开源应用项目
- Android开发者必须深入学习的10个应用开源项目
- 【移动生活】Google项目副总裁安迪·鲁宾谈Android
- Android开发者必须深入学习的10个应用开源项目