/* Copyright 2012 ESRI
*
* All rights reserved under the copyright laws of the United States
* and applicable international laws, treaties, and conventions.
*
* You may freely redistribute and use this sample code, with or
* without modification, provided you include the original copyright
* notice and use restrictions.
*
* See the �Sample code usage restrictions� document for further information.
*
*/
package com.esri.arcgis.android.samples.localtiledlayer;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.mapapi.BMapManager;
import com.baidu.mapapi.MKGeneralListener;
import com.baidu.mapapi.map.MKEvent;
import com.esri.android.map.GraphicsLayer;
import com.esri.android.map.MapView;
import com.esri.android.map.ags.ArcGISLocalTiledLayer;
import com.esri.core.geometry.GeometryEngine;
import com.esri.core.geometry.Point;
import com.esri.core.geometry.SpatialReference;
import com.esri.core.map.Graphic;
import com.esri.core.symbol.SimpleMarkerSymbol;
import com.esri.core.symbol.SimpleMarkerSymbol.STYLE;
public class LocalTiledLayer extends Activity {
private MapView map = null;
private ArcGISLocalTiledLayer local;
//提示信息
private Toast toast;
/**
* GPS定位
*/
private GraphicsLayer gLayerGps;
private Point wgspoint;
private Point mapPoint;
private Button btnGPS;
//定位SDK的核心类
private LocationClient mLocClient;
//是否手动触发请求定位
private boolean isRequest = true;
//是否首次定位
private boolean isFirstLoc = true;
//地图显示
private BMapManager mBMapMan = null;
private int requestTime=0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
map = (MapView) findViewById(R.id.map);
mLocClient = new LocationClient(getApplicationContext());
mLocClient.registerLocationListener(new BDLocationListenerImpl());//注册定位监听接口
/**
* LocationClientOption 该类用来设置定位SDK的定位方式。
*/
LocationClientOption option = new LocationClientOption();
option.setOpenGps(true); //打开GPRS
option.setAddrType("all");//返回的定位结果包含地址信息
option.setCoorType("bd09ll");//返回的定位结果是百度经纬度,默认值gcj02
option.setPriority(LocationClientOption.GpsFirst); // 设置GPS优先
option.setScanSpan(1000); //设置发起定位请求的间隔时间为1s
option.disableCache(true);//启用缓存定位
mLocClient.setLocOption(option); //设置定位参数
local = new ArcGISLocalTiledLayer("file:///storage/sdcard0/arcgis/base_map.tpk");
map.addLayer(local);
gLayerGps = new GraphicsLayer();
map.addLayer(gLayerGps);
//开始定位按钮
btnGPS=(Button)findViewById(R.id.btnStartGps);
btnGPS.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
mLocClient.start();//调用此方法开始定位
requestLocation();
}
});
}
public void requestLocation()
{
isRequest = true;
if(mLocClient != null && mLocClient.isStarted())
{
showToast("GPS正在定位……");
mLocClient.requestLocation();
}
else
{
Log.d("log", "locClient is null or not started");
}
}
public class MKGeneralListenerImpl implements MKGeneralListener
{
/**
* 一些网络状态的错误处理回调函数
*/
@Override
public void onGetNetworkState(int iError)
{
if (iError == MKEvent.ERROR_NETWORK_CONNECT)
{
showToast("您的网络出错啦!");
}
}
/**
* 授权错误的时候调用的回调函数
*/
@Override
public void onGetPermissionState(int iError)
{
if (iError == MKEvent.ERROR_PERMISSION_DENIED)
{
showToast("API KEY错误, 请检查!");
}
}
}
private void showToast(String msg)
{
if(toast == null)
{
toast = Toast.makeText(this, msg, Toast.LENGTH_SHORT);
}
else
{
toast.setText(msg);
toast.setDuration(Toast.LENGTH_SHORT);
}
toast.show();
}
/**
* 将GPS点标注在地图上
* @param 纬度
* @param 经度
*/
public void ShowGpsOnMap(double lon,double lat){
//清空定位图层
gLayerGps.removeAll();
//接收到的GPS的信号X(lat),Y(lon)
double locx = lon;
double locy = lat;
wgspoint = new Point(locx, locy);
mapPoint = (Point) GeometryEngine.project(wgspoint,SpatialReference.create(4326),map.getSpatialReference());
//图层的创建
Graphic graphic = new Graphic(mapPoint,new SimpleMarkerSymbol(Color.RED,18,STYLE.CIRCLE));
gLayerGps.addGraphic(graphic);
}
public class BDLocationListenerImpl implements BDLocationListener
{
/**
* 接收异步返回的定位结果,参数是BDLocation类型参数
*/
@Override
public void onReceiveLocation(BDLocation location)
{
if (location == null)
{
return;
}
StringBuffer sb = new StringBuffer(256);
sb.append("time : ");
sb.append(location.getTime());
sb.append("\nerror code : ");
sb.append(location.getLocType());
sb.append("\nlatitude : ");
sb.append(location.getLatitude());
sb.append("\nlontitude : ");
sb.append(location.getLongitude());
sb.append("\nradius : ");
sb.append(location.getRadius());
if (location.getLocType() == BDLocation.TypeGpsLocation)
{
sb.append("\nspeed : ");
sb.append(location.getSpeed());
sb.append("\nsatellite : ");
sb.append(location.getSatelliteNumber());
}
else if (location.getLocType() == BDLocation.TypeNetWorkLocation)
{
sb.append("\naddr : ");
sb.append(location.getAddrStr());
}
Log.e("log", sb.toString());
if(isFirstLoc || isRequest)
{
isRequest = false;
}
isFirstLoc = false;
double lat=location.getLatitude();
double lon=location.getLongitude();
ShowGpsOnMap(lon,lat);
}
@Override
public void onReceivePoi(BDLocation arg0) {
// TODO Auto-generated method stub
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
LocalTiledLayer.zip (45个子文件)
LocalTiledLayer
.project 818B
project.properties 361B
src
com
esri
arcgis
android
samples
localtiledlayer
LocalTiledLayer.java 7KB
AndroidManifest.xml 4KB
res
drawable-ldpi
icon.png 2KB
drawable-hdpi
icon.png 4KB
drawable-mdpi
icon.png 3KB
layout
main.xml 750B
values
strings.xml 185B
.settings
org.eclipse.jdt.core.prefs 177B
gen
com
esri
arcgis
android
samples
localtiledlayer
Manifest.java 438B
BuildConfig.java 189B
R.java 818B
libs
armeabi-v7a
libruntimecore_java.so 11.42MB
locSDK_3.1.jar 97KB
armeabi
libruntimecore_java.so 10.23MB
baidumapapi_v2_4_1.jar 792KB
.classpath 563B
bin
resources.ap_ 12KB
classes
com
esri
arcgis
android
samples
localtiledlayer
R$layout.class 481B
BuildConfig.class 403B
R$drawable.class 487B
R$attr.class 427B
LocalTiledLayer$1.class 1KB
LocalTiledLayer$BDLocationListenerImpl.class 2KB
Manifest$permission.class 598B
LocalTiledLayer$MKGeneralListenerImpl.class 1KB
Manifest.class 462B
LocalTiledLayer.class 6KB
R$id.class 503B
R.class 734B
R$string.class 514B
AndroidManifest.xml 4KB
dexedLibs
annotations-1fd7a29da286dc4b7e02d911680249a0.jar 943B
ArcGIS_Android-d6102fd5f491d8444aafb311e7af30b5.jar 537KB
baidumapapi_v2_4_1-ef98c5e8cb49385b6ba904debc101e4a.jar 639KB
jackson-mapper-lgpl-1.9.5-ef30a0b72c96d59812c3fa4d6e306537.jar 264KB
locSDK_3.1-350c20de61de9016fa5940853026a5f8.jar 53KB
jackson-core-lgpl-1.9.5-87b7f787741474d9599c179f3c6043b4.jar 118KB
jarlist.cache 120B
res
crunch
drawable-ldpi
icon.png 2KB
drawable-hdpi
icon.png 4KB
drawable-mdpi
icon.png 2KB
LocalTiledLayer.apk 8.79MB
classes.dex 3MB
共 45 条
- 1
牛老师讲GIS
- 粉丝: 5928
- 资源: 63
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页