电脑百度地图怎么定位?

怎样在电脑的百度地图里定位自己在的位置_百度知道
怎样在电脑的百度地图里定位自己在的位置
电脑的百度地图是不能定位的,不过可以标注自己的位置,标注后就会显示位置了。百度地图免费标注的方法:1、打开百度地图首页,如果没有百度帐号的,可以去注册一个百度帐号,并完善信息,然后点击右上角的&商户免费标注&。2、可以看到有两个提示信息”如果您的商铺在百度地图上已经存在,搜索到后您可以直接认领“、”如果您的商铺在百度地图上还不存在,您可以先标注再进行认领“,输入自己的店名,查询是否已标记。3、输入”百度公司”为示例示,如果存在,就可以直接认领了4、如果没有相关的店名,就需要先进行标注,如以“无限公司”为例,地图上无相关信息,就可点“免费添加标注”进行添加标注5、这里需要填写相关的店铺信息即可,然后提交就可以了。提交申请后,需要5-7天的审核期,请耐心等待。
其他类似问题
为您推荐:
百度地图的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁Android 百度地图定位(手动+自动)
安卓开发教程-android100学习网
Android 百度地图定位(手动+自动)
安卓开发教程
近由于项目需要,研究了下百度地图定位,他们提供的实例基本都是用监听器实现自动定位的。我想实现一种效果:当用户进入UI时,不定位,用户需要定位的时候,自己手动点击按钮,再去定位当前位置。 经过2天研究和...
近由于项目需要,研究了下百度地图定位,他们提供的实例基本都是用监听器实现自动定位的。我想实现一种效果:当用户进入UI时,不定位,用户需要定位的时候,自己手动点击按钮,再去定位当前位置。& 经过2天研究和咨询,找到了解决方案,在此备忘一下。
&& 注意:定位使用真机才能够真正定位;模拟器的话,在DDMS中的Emulator Control中,选择Manual,下面单选按钮选择Decimal,然后填写经纬度,send后,再点击定位我的位置按钮,就能定位了(这应该算是固定定位,哈哈。。。)、
&&&&&&&& 1、第一步当然是获取一个针对自己项目的key值。/wiki/static/imap/key/
2、使用百度API是有前提的,摘自百度:首先将API包括的两个文件baidumapapi.jar和 libBMapApiEngine.so拷贝到工程根目录及libs\armeabi目录下,并在工程属性-&Java Build Path-&Libraries中选择&Add JARs&,选定baidumapapi.jar,确定后返回,这样您就可以在您的程序中使用API了。(这两个文件见附件)。
3、按照自己的需求写一个layout,我的如下:
&&&& &?xml version=&1.0& encoding=&utf-8&?&
&LinearLayout&
& xmlns:android=&/apk/res/android&&
& android:orientation=&vertical&&
& android:layout_width=&fill_parent&&
& android:layout_height=&fill_parent&&
& &TextView&&
&&& android:id=&@+id/myLocation_id&&&
&&& android:layout_width=&fill_parent&&&
&&& android:layout_height=&wrap_content&&
&&& android:textSize=&15dp&&
&&& android:gravity=&center_horizontal&&
&&& android:textColor=&@drawable/black&&
&&& android:background=&@drawable/gary&&
& &com.baidu.mapapi.MapView android:id=&@+id/bmapsView&&
&&& android:layout_width=&fill_parent& android:layout_height=&fill_parent&&&
&&& android:clickable=&true&& android:layout_weight=&1&&&&&
& &Button&&
&&&&& android:layout_width=&wrap_content&&&
&&&&& android:layout_height=&wrap_content&&&
&&&&& android:id=&@+id/location_button_id&&&
&&&&& android:text=&@string/location_button_text&&
&/LinearLayout&&
需要特别注意的是:&com.baidu.mapapi.MapView& /& 这玩意。
4、写一个MapApplication实现application,提供全局的BMapManager,以及其初始化。
public BMapManager mapManager =&
static MapA&
public String mStrKey = &你申请的key值&;&
@Override&
public void onCreate() {&
&&& mapManager = new BMapManager(this);&
&&& mapManager.init(mStrKey, new MyGeneralListener());&
@Override&
//建议在您app的退出之前调用mapadpi的destroy()函数,避免重复初始化带来的时间消耗&
public void onTerminate() {&
&&& // TODO Auto-generated method stub&
&&& if(mapManager != null)&
&&&&&&& mapManager.destroy();&
&&&&&&& mapManager =&
&&& super.onTerminate();&
static class MyGeneralListener implements MKGeneralListener{&
&&& @Override&
&&& public void onGetNetworkState(int arg0) {&
&&&&&&& Toast.makeText(MapApplication.app.getApplicationContext(), &您的网络出错啦!&,&
&&&&&&&&&&&&&&& Toast.LENGTH_LONG).show();&
&&& @Override&
&&& public void onGetPermissionState(int iError) {&
&&&&&&& if (iError ==& MKEvent.ERROR_PERMISSION_DENIED) {&
&&&&&&&&&&& // 授权Key错误:&
&&&&&&&&&&& Toast.makeText(MapApplication.app.getApplicationContext(),&您的授权Key不正确!&,&
&&&&&&&&&&&&&&&&&&& Toast.LENGTH_LONG).show();&
&&&&&&& }&
5、接下来就是按照百度api写定位代码了,使用handler机制去添加定位图层,需要说明的都在注释上了。&
&&&&&& private BMapManager mBMapMan =&
private MapView mMapView =&
private MapController bMapC&
private MKLocationManager mkLocationM&
private MKSearch mkS&
private TextView address_&& //定位到的位置信息&
private ProgressD&
private List&HotelInfo& hotelL&
private int distance = 1000;& //查询的范围(单位:m)&
&& Handler handler = new Handler(){&
&&& @Override&
&&& public void handleMessage(Message msg) {&
&&&&&&& double lat = msg.getData().getDouble(&lat&);&
&&&&&&& double lon = msg.getData().getDouble(&lon&);&
&&&&&&& if(lat!=0&&lon!=0){&
&&&&&&&&&&& GeoPoint point = new GeoPoint(&
&&&&&&&&&&&&&&&&&&& (int) (lat * 1E6),&
&&&&&&&&&&&&&&&&&&& (int) (lon * 1E6));&
&&&&&&&&&&& bMapController.animateTo(point);& //设置地图中心点&
&&&&&&&&&&& bMapController.setZoom(15);&
&&&&&&&&&&&&&
&&&&&&&&&&& mkSearch.reverseGeocode(point);&& //解析地址(异步方法)&
&&&&&&&&&&&&&
&&&&&&&&&&& MyLocationOverlay myLoc = new MyLocationOverlayFromMap(ShowMapAct.this,mMapView);&
&&&&&&&&&&& myLoc.enableMyLocation();&& // 启用定位&
&&&&&&&&&&& myLoc.enableCompass();&&&&& // 启用指南针&
&&&&&&&&&&& mMapView.getOverlays().add(myLoc);&
&&&&&&& }else{&
&&&&&&&&&&& Toast.makeText(ShowMapAct.this, &没有加载到您的位置&, Toast.LENGTH_LONG).show();&
&&&&&&& }&
&&&&&&& if(hotelList!=null){&
&&&&&&&&&&& Drawable marker = getResources().getDrawable(R.drawable.iconmarka);& //设置marker&
&&&&&&&&&&& marker.setBounds(0, 0, marker.getIntrinsicWidth(), marker.getIntrinsicHeight());&& //为maker定义位置和边界&
&&&&&&&&&&& mMapView.getOverlays().add(new OverItemList(marker,hotelList,ShowMapAct.this,bMapController));&
&&&&&&& }else if(hotelList==null&&lat!=0&&lon!=0){&
&&&&&&&&&&& Toast.makeText(ShowMapAct.this, &网络异常,没有获取到酒店信息。&, Toast.LENGTH_LONG).show();&
&&&&&&& }&
&&&&&&& if(dialog!=null)& dialog.dismiss();&
@Override&
protected void onCreate(Bundle savedInstanceState) {&
&&& distance = getIntent().getExtras().getInt(&distance&);&& //获取查询范围&
&&& super.onCreate(savedInstanceState);&
&&& setContentView(R.layout.location);&
&&& mMapView = (MapView)findViewById(R.id.bmapsView);&& //初始化一个mapView& 存放Map&
&&& init();& //初始化地图管理器&
&&& super.initMapActivity(mBMapMan);&
&&& address_view = (TextView)findViewById(R.id.myLocation_id);&
&&& SpannableStringBuilder style = new SpannableStringBuilder(String.format(getResources().getString(R.string.location_text),&位置不详&));&
&&& style.setSpan(new ForegroundColorSpan(Color.RED), 5, style.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);&
&&& address_view.setText(style);&
&&& Button location_button = (Button)findViewById(R.id.location_button_id);&
&&& location_button.setOnClickListener(new View.OnClickListener(){&
&&&&&&& @Override&
&&&&&&& public void onClick(View v) {&
&&&&&&&&&&&& dialog = ProgressDialog.show(ShowMapAct.this, &&, &数据加载中,请稍后.....&);&
&&&&&&&&&&&& new Thread(new MyThread()).start();&
&&&&&&& }&
&&& mkSearch = new MKSearch();&& //初始化一个MKSearch,根据location解析详细地址&
&&& mkSearch.init(mBMapMan, this);&
&&&&&& mMapView.setBuiltInZoomControls(true);&& //启用内置的缩放控件&
&&&&&& bMapController = mMapView.getController();&
&&&&&& GeoPoint defaultPoint = new GeoPoint((int) (39.920934 * 1E6),(int) (116.412817 * 1E6));& //用给定的经纬度构造一个GeoPoint,单位是微度 (度 * 1E6)&
&&&&&& bMapController.setCenter(defaultPoint);& //设置地图中心点&
&&&&&& bMapController.setZoom(12);& //设置地图zoom级别&
&&&&&& mkLocationManager = mBMapMan.getLocationManager();&
* 初始化地图管理器BMapManager
public void init(){&
&&& MapApplication app = (MapApplication)getApplication();&
&&&&&& if (app.mapManager == null) {&
&&&&&&& app.mapManager = new BMapManager(getApplication());&
&&&&&&& app.mapManager.init(app.mStrKey, new MapApplication.MyGeneralListener());&
&&&&&& mBMapMan = app.mapM&
@Override&
protected void onDestroy() {&
&&& MapApplication app = (MapApplication)getApplication();&
&&& if (mBMapMan != null) {&
&&&&&&& mBMapMan.destroy();&
&&&&&&& app.mapManager.destroy();&
&&&&&&& app.mapManager =&
&&&&&&& mBMapMan =&
&&& super.onDestroy();&
&& @Override&&&
&& protected void onPause() {&&&
&&&&&& if (mBMapMan != null) {&&&
&&&&&&&&&& // 终止百度地图API& &
&&&&&&& mBMapMan.stop();&&&
&&&&&& }&&&
&&&&&& super.onPause();&&&
&& @Override&&&
&& protected void onResume() {&
&&&&&& if (mBMapMan != null) {&&&
&&&&&&&&&& // 开启百度地图API& &
&&&&&&& mBMapMan.start();&&&
&&&&&& }&&&
&&&&&& super.onResume();&&&
@Override&
protected boolean isRouteDisplayed() {&
@Override&
public void onGetAddrResult(MKAddrInfo result, int iError) {&
&&& if(result==null)&
&&& SpannableStringBuilder style = new SpannableStringBuilder(String.format(getResources().getString(R.string.location_text),result.strAddr));&
&&& style.setSpan(new ForegroundColorSpan(Color.RED), 5, style.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);&
&&& address_view.setText(style);&
&&& if(dialog!=null) dialog.dismiss();&
@Override&
public void onGetDrivingRouteResult(MKDrivingRouteResult arg0, int arg1) {}&
@Override&
public void onGetPoiResult(MKPoiResult arg0, int arg1, int arg2) {}&
@Override&
public void onGetTransitRouteResult(MKTransitRouteResult arg0, int arg1) {}&
@Override&
public void onGetWalkingRouteResult(MKWalkingRouteResult arg0, int arg1) {}&
* 重新定位,加载数据
* @author Administrator
class MyThread implements Runnable{&
&&& @Override&
&&& public void run() {&
&&&&&&& /**
&&&&&&&&& * 最重要的就是这个玩意
&&&&&&&&& * 由于LocationListener获取第一个位置修正的时间会很长,为了避免用户等待,
&&&&&&&&& * 在LocationListener获取第一个更精确的位置之前,应当使用getLocationInfo() 获取一个缓存的位置
&&&&&&&&& */&
&&&&&&& Location location = mkLocationManager.getLocationInfo();&
&&&&&&& double lat = 0d,lon = 0d;&
&&&&&&& if(location!=null){&& //定位到位置&
&&&&&&&&&&& String coordinate = location.getLatitude()+&,&+location.getLongitude();&
&&&&&&&&&&& HotelRemoteData hotelData = new HotelRemoteData();&
&&&&&&&&&&& /**
&&&&&&&&&&&& * 远程获取酒店列表数据
&&&&&&&&&&&& */&
&&&&&&&&&&& hotelList = hotelData.getHotelToMap(coordinate,distance);&
&&&&&&&&&&& lat = location.getLatitude();&
&&&&&&&&&&& lon = location.getLongitude();&
&&&&&&& }&
&&&&&&& Message msg = new Message();&
&&&&&&& Bundle data = new Bundle();&
&&&&&&& data.putDouble(&lat&, lat);&
&&&&&&& data.putDouble(&lon&, lon);&
&&&&&&& msg.setData(data);&
&&&&&&& handler.sendMessage(msg);&
& 6、还有一种就是百度示例相当推荐的,也是加载定位位置速度比较快的,那就是通过定位监听器来定位信息。没啥难的,照着百度的示例写,都能搞定。
LocationListener listener = new LocationListener() {&
&&& @Override&
&&& /** 位置变化,百度地图即会调用该方法去获取位置信息。
&&&&& * (我测试发现就算手机不动,它也会偶尔重新去加载位置;只要你通过重力感应,他就一定会重新加载)
&&& public void onLocationChanged(Location location) {&
&&&&& GeoPoint gp =& new GeoPoint((int) (location.getLatitude() * 1E6), (int) (location.getLongitude() * 1E6));&& //通过地图上的经纬度转换为地图上的坐标点&
&&&&& bMapController.animateTo(gp);& //动画般的移动到定位的位置&& & 最近使用百度地图,查看了官方的说明,然后做了一个Demo,作为入门,如果看了我之前的代码,有一个习惯就是使用代码写布局,感觉这样比较快,习惯而已。& & 源码如下:& & [java]& & package com.zhangjie.& & import android.os.B& & import android.os.V& & import android.app.A& & import android.app.S& & import android.util.DisplayM& & import android.util.L& & import android.view.M& & import android.view.V& & import android.view.View.OnClickL& & import android.widget.B& & import android.widget.LinearL& & import android.widget.RelativeL& & import android.widget.TextV& & import com.baidu.location.BDL& & import com.baidu.location.BDLocationL& & import com.baidu.location.LocationC& & import com.baidu.location.LocationClientO& & import com.baidu.location.BDNotifyL//假如用到位置提醒功能,需要import该类& & public class Local extends Activity implements OnClickListener{& & @Override& & protected void onCreate(Bundle savedInstanceState) {& & super.onCreate(savedInstanceState);& & getDisplayMetrics();& & initLayout();& & setContentView(Parent);& & myListener = new MyLocationListener();& & mLocationClient = new LocationClient(getApplicationContext());& & mLocationClient.registerLocationListener(myListener);& & //设置定位参数包括:定位模式(单次定位,定时定位),返回坐标类型,是否打开GPS等等& & ption = new LocationClientOption();& & option.setOpenGps(true);& & option.setAddrType("all");//返回定位结果包含地址信息& & option.setCoorType("bd0911");//返回的定位结果是百度经纬度,默认值gcj02& & option.setScanSpan(5000);//设置发起请求的时间间隔为5000ms& & option.disableCache(true);//禁止开启缓存定位& & option.setPoiNumber(5);//最多返回POI个数& & option.setPoiDistance(1000);//poi查询距离& & option.setPoiExtraInfo(true);//是否需要POI的电话和地址等详细信息& & mLocationClient.setLocOption(option);& & mLocationClient.start();& & }& & /**& & * 初始化布局& & */& & public void initLayout(){& & Parent = new RelativeLayout(this);& & bottomLayout = new LinearLayout(this);& & bottomLayout.setId(10);& & contentTextView = new TextView(this);& & contentTextView.setText(R.string.content);& & localButton = new Button(this);& & localButton.setText(R.string.localrequest);& & localButton.setId(11);& & localButton.setOnClickListener(this);& & poiButton = new Button(this);& & poiButton.setText(R.string.poirequest);& & poiButton.setId(12);& & poiButton.setOnClickListener(this);& & notifyButton = new Button(this);& & notifyButton.setText(R.string.notify);& & notifyButton.setId(13);& & notifyButton.setOnClickListener(this);& & fflineButton = new Button(this);& & offlineButton.setText(R.string.offine);& & offlineButton.setId(14);& & offlineButton.setOnClickListener(this);& & //設置底部佈局的button& & int disten = (Screen_width - dip2px(buttonWidth) * 4) / 5;& & LinearLayout.LayoutParams buttonInBottomLayoutParams = new LinearLayout.LayoutParams(dip2px(buttonWidth), dip2px(buttonHeight));& & buttonInBottomLayoutParams.leftMargin =& & bottomLayout.addView(localButton, buttonInBottomLayoutParams);& & bottomLayout.addView(poiButton, buttonInBottomLayoutParams);& & bottomLayout.addView(notifyButton, buttonInBottomLayoutParams);& & bottomLayout.addView(offlineButton, buttonInBottomLayoutParams);& & RelativeLayout.LayoutParams bottomInParentLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);& & bottomInParentLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);& & Parent.addView(bottomLayout, bottomInParentLayoutParams);& & //設置contentTextView佈局& & RelativeLayout.LayoutParams contentInParentLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);& & contentInParentLayoutParams.addRule(RelativeLayout.ABOVE, 10);& & Parent.addView(contentTextView, contentInParentLayoutParams);& & }& & @Override& & public void onClick(View v) {& & switch (v.getId()) {& & case 11:& & //发起定位请求。请求过程是异步的,定位结果在上面的监听函数onReceiveLocation中获取。& & if (mLocationClient != null && mLocationClient.isStarted()) {& & mLocationClient.requestLocation();& & }else {& & Log.e("LocSDK3", "locClient is null or not started");& & }& && & case 12:& & //发起POI查询请求。请求过程是异步的,定位结果在上面的监听函数onReceivePoi中获取& & if (mLocationClient != null && mLocationClient.isStarted()) {& & mLocationClient.requestPoi();& & }& && & case 13:& & if (!clickNotify) {& & clickNotify =& & //位置提醒最多提醒3次,3次过后将不再提醒。 假如需要再次提醒,或者要修改提醒点坐标,都可通过函数SetNotifyLocation()来实现& & //位置提醒相关代码& & mNotifyer = new NotifyLister();& & mNotifyer.SetNotifyLocation(42.37,113.6,3000,"gps");//4个参数代表要位置提醒的点的坐标,具体含义依次为:纬度,经度,距离范围,坐标系类型(gcj02,gps,bd09,bd09ll)& & mLocationClient.registerNotify(mNotifyer);& & }else {& & clickNotify =& & //取消位置提醒& & mLocationClient.removeNotifyEvent(mNotifyer);& & }& && & case 14:& & /*& & *&发起离线定位请求。请求过程是异步的,定位结果在上面的监听函数onReceiveLocation中获取。& & *&getLocTypte = BDLocation.TypteOfflineLocation || BDLocation.TypeOfflineLocationFail& & *&表示是离线定位请求返回的定位结果& & */& & if (mLocationClient != null && mLocationClient.isStarted()) {& & mLocationClient.requestOfflineLocation();& & }& && & }& & }& & //获取屏幕的宽度,高度和密度以及dp / px& & public void getDisplayMetrics() {& & DisplayMetrics dm = new DisplayMetrics();& & dm = getApplicationContext().getResources().getDisplayMetrics();& & Screen_width = dm.widthP& & Screen_height = dm.heightP& & scale = getResources().getDisplayMetrics().& & }& & public int dip2px(float dpValue) {& & return (int)(dpValue * scale + 0.5f);& & }& & @Override& & public boolean onCreateOptionsMenu(Menu menu) {& & getMenuInflater().inflate(R.menu.local, menu);& && & }& & @Override& & protected void onStop() {& & super.onStop();& & if (mLocationClient != null) {& & mLocationClient.stop();& & mLocationClient =& & }& & }& & public class MyLocationListener implements BDLocationListener{& & //接收异步返回的定位结果,参数是BDLocation类型参数& & @Override& & public void onReceiveLocation(BDLocation location) {& & if (location == null) {& && & }& & StringBuffer sb = new StringBuffer(256);& & sb.append("time: ");& & sb.append(location.getTime());& & sb.append("\nerror code: ");& & sb.append(location.getLocType());& & sb.append("\nlontitude: ");& & sb.append(location.getLongitude());& & sb.append("\nradius: ");& & sb.append(location.getRadius());& & if (location.getLocType() == BDLocation.TypeGpsLocation) {& & sb.append("\nspedd: ");& & sb.append(location.getSpeed());& & sb.append("\nsatellite: ");& & sb.append(location.getSatelliteNumber());& & }else if(location.getLocType() == BDLocation.TypeNetWorkLocation){& & sb.append("\naddr: ");& & sb.append(location.getAddrStr());& & }else if(location.getLocType() == BDLocation.TypeOffLineLocation || location.getLocType() == BDLocation.TypeOffLineLocationNetworkFail){& & }& & if (contentTextView != null) {& & contentTextView.setText(sb.toString());& & }& & }& & //接收异步返回的POI查询结果,参数是BDLocation类型参数& & @Override& & public void onReceivePoi(BDLocation arg0) {& & }& & }& & //BDNotifyListener实现& & public class NotifyLister extends BDNotifyListener{& & public void onNotify(BDLocationListener mListener, float distance){& & if (mVibrator == null) {& & mVibrator = (Vibrator)getApplication().getSystemService(Service.VIBRATOR_SERVICE);& & }& & mVibrator.vibrate(1000);//振动提醒已到设定位置附近& & }& & }& & public LocationClient mLocationClient =& & LocationClientO& & public BDLocationListener myL& & public NotifyLister mN& & public Vibrator mV& & private TextView contentTextV& & private Button localB& & private Button poiB& & private Button notifyB& & private Button offlineB& & private RelativeLayout P& & private LinearLayout bottomL& & public int Screen_& & public int Screen_& && & public int buttonWidth = 130;//dp& & public int buttonHeight = 50;//dp& & public boolean clickNotify =& & }& & package com.zhangjie.& & import android.os.B& & import android.os.V& & import android.app.A& & import android.app.S& & import android.util.DisplayM& & import android.util.L& & import android.view.M& & import android.view.V& & import android.view.View.OnClickL& & import android.widget.B& & import android.widget.LinearL& & import android.widget.RelativeL& & import android.widget.TextV& & import com.baidu.location.BDL& & import com.baidu.location.BDLocationL& & import com.baidu.location.LocationC& & import com.baidu.location.LocationClientO& & import com.baidu.location.BDNotifyL//假如用到位置提醒功能,需要import该类& & public class Local extends Activity implements OnClickListener{& & @Override& & protected void onCreate(Bundle savedInstanceState) {& & super.onCreate(savedInstanceState);& & getDisplayMetrics();& & initLayout();& & setContentView(Parent);& & myListener = new MyLocationListener();& & mLocationClient = new LocationClient(getApplicationContext());& & mLocationClient.registerLocationListener(myListener);& & //设置定位参数包括:定位模式(单次定位,定时定位),返回坐标类型,是否打开GPS等等& & ption = new LocationClientOption();& & option.setOpenGps(true);& & option.setAddrType("all");//返回定位结果包含地址信息& & option.setCoorType("bd0911");//返回的定位结果是百度经纬度,默认值gcj02& & option.setScanSpan(5000);//设置发起请求的时间间隔为5000ms& & option.disableCache(true);//禁止开启缓存定位& & option.setPoiNumber(5);//最多返回POI个数& & option.setPoiDistance(1000);//poi查询距离& & option.setPoiExtraInfo(true);//是否需要POI的电话和地址等详细信息& & mLocationClient.setLocOption(option);& & mLocationClient.start();& & }& & /**& & * 初始化布局& & */& & public void initLayout(){& & Parent = new RelativeLayout(this);& & bottomLayout = new LinearLayout(this);& & bottomLayout.setId(10);& & contentTextView = new TextView(this);& & contentTextView.setText(R.string.content);& & localButton = new Button(this);& & localButton.setText(R.string.localrequest);& & localButton.setId(11);& & localButton.setOnClickListener(this);& & poiButton = new Button(this);& & poiButton.setText(R.string.poirequest);& & poiButton.setId(12);& & poiButton.setOnClickListener(this);& & notifyButton = new Button(this);& & notifyButton.setText(R.string.notify);& & notifyButton.setId(13);& & notifyButton.setOnClickListener(this);& & fflineButton = new Button(this);& & offlineButton.setText(R.string.offine);& & offlineButton.setId(14);& & offlineButton.setOnClickListener(this);& & //設置底部佈局的button& & int disten = (Screen_width - dip2px(buttonWidth) * 4) / 5;& & LinearLayout.LayoutParams buttonInBottomLayoutParams = new LinearLayout.LayoutParams(dip2px(buttonWidth), dip2px(buttonHeight));& & buttonInBottomLayoutParams.leftMargin =& & bottomLayout.addView(localButton, buttonInBottomLayoutParams);& & bottomLayout.addView(poiButton, buttonInBottomLayoutParams);& & bottomLayout.addView(notifyButton, buttonInBottomLayoutParams);& & bottomLayout.addView(offlineButton, buttonInBottomLayoutParams);& & RelativeLayout.LayoutParams bottomInParentLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);& & bottomInParentLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);& & Parent.addView(bottomLayout, bottomInParentLayoutParams);& & //設置contentTextView佈局& & RelativeLayout.LayoutParams contentInParentLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);& & contentInParentLayoutParams.addRule(RelativeLayout.ABOVE, 10);& & Parent.addView(contentTextView, contentInParentLayoutParams);& & }& & @Override& & public void onClick(View v) {& & switch (v.getId()) {& & case 11:& & //发起定位请求。请求过程是异步的,定位结果在上面的监听函数onReceiveLocation中获取。& & if (mLocationClient != null && mLocationClient.isStarted()) {& & mLocationClient.requestLocation();& & }else {& & Log.e("LocSDK3", "locClient is null or not started");& & }& && & case 12:& & //发起POI查询请求。请求过程是异步的,定位结果在上面的监听函数onReceivePoi中获取& & if (mLocationClient != null && mLocationClient.isStarted()) {& & mLocationClient.requestPoi();& & }& && & case 13:& & if (!clickNotify) {& & clickNotify =& & //位置提醒最多提醒3次,3次过后将不再提醒。 假如需要再次提醒,或者要修改提醒点坐标,都可通过函数SetNotifyLocation()来实现& & //位置提醒相关代码& & mNotifyer = new NotifyLister();& & mNotifyer.SetNotifyLocation(42.37,113.6,3000,"gps");//4个参数代表要位置提醒的点的坐标,具体含义依次为:纬度,经度,距离范围,坐标系类型(gcj02,gps,bd09,bd09ll)& & mLocationClient.registerNotify(mNotifyer);& & }else {& & clickNotify =& & //取消位置提醒& & mLocationClient.removeNotifyEvent(mNotifyer);& & }& && & case 14:& & /*& & *&发起离线定位请求。请求过程是异步的,定位结果在上面的监听函数onReceiveLocation中获取。& & *&getLocTypte = BDLocation.TypteOfflineLocation || BDLocation.TypeOfflineLocationFail& & *&表示是离线定位请求返回的定位结果& & */& & if (mLocationClient != null && mLocationClient.isStarted()) {& & mLocationClient.requestOfflineLocation();& & }& && & }& & }& & //获取屏幕的宽度,高度和密度以及dp / px& & public void getDisplayMetrics() {& & DisplayMetrics dm = new DisplayMetrics();& & dm = getApplicationContext().getResources().getDisplayMetrics();& & Screen_width = dm.widthP& & Screen_height = dm.heightP& & scale = getResources().getDisplayMetrics().& & }& & public int dip2px(float dpValue) {& & return (int)(dpValue * scale + 0.5f);& & }& & @Override& & public boolean onCreateOptionsMenu(Menu menu) {& & getMenuInflater().inflate(R.menu.local, menu);& && & }& & @Override& & protected void onStop() {& & super.onStop();& & if (mLocationClient != null) {& & mLocationClient.stop();& & mLocationClient =& & }& & }& & public class MyLocationListener implements BDLocationListener{& & //接收异步返回的定位结果,参数是BDLocation类型参数& & @Override& & public void onReceiveLocation(BDLocation location) {& & if (location == null) {& && & }& & StringBuffer sb = new StringBuffer(256);& & sb.append("time: ");& & sb.append(location.getTime());& & sb.append("\nerror code: ");& & sb.append(location.getLocType());& & sb.append("\nlontitude: ");& & sb.append(location.getLongitude());& & sb.append("\nradius: ");& & sb.append(location.getRadius());& & if (location.getLocType() == BDLocation.TypeGpsLocation) {& & sb.append("\nspedd: ");& & sb.append(location.getSpeed());& & sb.append("\nsatellite: ");& & sb.append(location.getSatelliteNumber());& & }else if(location.getLocType() == BDLocation.TypeNetWorkLocation){& & sb.append("\naddr: ");& & sb.append(location.getAddrStr());& & }else if(location.getLocType() == BDLocation.TypeOffLineLocation || location.getLocType() == BDLocation.TypeOffLineLocationNetworkFail){& & }& & if (contentTextView != null) {& & contentTextView.setText(sb.toString());& & }& & }& & //接收异步返回的POI查询结果,参数是BDLocation类型参数& & @Override& & public void onReceivePoi(BDLocation arg0) {& & }& & }& & //BDNotifyListener实现& & public class NotifyLister extends BDNotifyListener{& & public void onNotify(BDLocationListener mListener, float distance){& & if (mVibrator == null) {& & mVibrator = (Vibrator)getApplication().getSystemService(Service.VIBRATOR_SERVICE);& & }& & mVibrator.vibrate(1000);//振动提醒已到设定位置附近& & }& & }& & public LocationClient mLocationClient =& & LocationClientO& & public BDLocationListener myL& & public NotifyLister mN& & public Vibrator mV& & private TextView contentTextV& & private Button localB& & private Button poiB& & private Button notifyB& & private Button offlineB& & private RelativeLayout P& & private LinearLayout bottomL& & public int Screen_& & public int Screen_& && & public int buttonWidth = 130;//dp& & public int buttonHeight = 50;//dp& & public boolean clickNotify =& & }
声明:该文章系网友上传分享,此内容仅代表网友个人经验或观点,不代表本网站立场和观点;若未进行原创声明,则表明该文章系转载自互联网;若该文章内容涉嫌侵权,请及时向
上一篇:下一篇:
相关经验教程
的原创经验被浏览,获得 ¥0.001 收益
的原创经验被浏览,获得 ¥0.001 收益
的原创经验被浏览,获得 ¥0.005 收益
的原创经验被浏览,获得 ¥0.001 收益
的原创经验被浏览,获得 ¥0.001 收益
的原创经验被浏览,获得 ¥0.001 收益
的原创经验被浏览,获得 ¥0.001 收益
的原创经验被浏览,获得 ¥0.001 收益
的原创经验被浏览,获得 ¥0.005 收益
的原创经验被浏览,获得 ¥0.005 收益
的原创经验被浏览,获得 ¥0.001 收益
的原创经验被浏览,获得 ¥0.001 收益
的原创经验被浏览,获得 ¥0.005 收益
的原创经验被浏览,获得 ¥0.005 收益
的原创经验被浏览,获得 ¥0.001 收益
的原创经验被浏览,获得 ¥0.005 收益
的原创经验被浏览,获得 ¥0.001 收益
的原创经验被浏览,获得 ¥0.005 收益
的原创经验被浏览,获得 ¥0.005 收益
的原创经验被浏览,获得 ¥0.005 收益
的原创经验被浏览,获得 ¥0.005 收益
的原创经验被浏览,获得 ¥0.001 收益
的原创经验被浏览,获得 ¥0.001 收益
的原创经验被浏览,获得 ¥0.002 收益}

我要回帖

更多关于 百度地图 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信