高德地图GPS定位

package com.cjy.map;

import com.autonavi.mapapi.GeoPoint;
import com.autonavi.mapapi.LocationManagerProxy;
import com.autonavi.mapapi.LocationProviderProxy;
import com.autonavi.mapapi.MapActivity;
import com.autonavi.mapapi.MapController;
import com.autonavi.mapapi.MapView;
import com.autonavi.mapapi.MyLocationOverlay;

import android.content.Context;
//
//import android.location.Location;
//import android.location.LocationListener;
//import android.location.LocationManager;
import android.location.Location;
import android.location.LocationListener;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;

public class MapGdActivity extends MapActivity {
 /** Called when the activity is first created. */
 MapView map = null;
 MapController ctrlMap = null;
 MyLocationOverlay mylocTest;
 GeoPoint point;

 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

  map = (MapView) findViewById(R.id.mylocationview);
  map.setBuiltInZoomControls(true); //
  ctrlMap = map.getController();
  // 得到mMapView的控制权,可以用它控制和驱动平移和缩放
  point = new GeoPoint((int) (34.299999 * 1E6),// 西安的经纬度
    (int) (108.930000 * 1E6)); // 用给定的经纬度构造一个GeoPoint,单位是微度 (度 * //
           // 1E6)
  ctrlMap.setCenter(point); // 设置地图中心点
  ctrlMap.setZoom(12); // 设置地图zoom级别
  //map.setTraffic(true);//设置地图为交通模式
  //map.setStreetView(true);
  //设置为卫星模式
  map.setSatellite(true);
  ctrlMap = map.getController();
  mylocTest = new MyLocationOverlay(MapGdActivity.this, map);
  mylocTest.enableMyLocation();
  mylocTest.enableCompass(); // 打开指南针
  map.getOverlays().add(mylocTest);
  LocationManagerProxy managerProxy = new LocationManagerProxy(this);
  managerProxy.requestLocationUpdates(LocationProviderProxy.AutonaviCellProvider,
    2000, 0, locationListener);

 }

 private void getLocationInfo(Location location) {
  String latLongInfo;
  TextView locationText = (TextView) findViewById(R.id.tv);
  if (location != null) {
   double lat = location.getLatitude();
   double lng = location.getLongitude();
   latLongInfo = "Lat: " + lat + "\nLong: " + lng;
  } else {
   latLongInfo = "No location found";
  }
  locationText.setText("Your Current Position is:\n" + latLongInfo);
 }

 private final LocationListener locationListener = new LocationListener() {
  public void onLocationChanged(Location location) {
   Log.e(MapGdActivity.class.getName(), "onLocationChanged");
   getLocationInfo(location);
   Toast.makeText(
     MapGdActivity.this,
     location.getAltitude() + "---" + location.getLatitude()
       + "---" + location.getLongitude(),
     Toast.LENGTH_LONG).show();
  }

  public void onProviderDisabled(String provider) {
   // TODO Auto-generated method stub
   Log.e(MapGdActivity.class.getName(), "onProviderDisabled=="
     + provider);
  }

  public void onProviderEnabled(String provider) {
   // TODO Auto-generated method stub
   Log.e(MapGdActivity.class.getName(), "onProviderEnabled=="
     + provider);
  }

  public void onStatusChanged(String provider, int status, Bundle extras) {
   // TODO Auto-generated method stub
   Log.e(MapGdActivity.class.getName(), "onStatusChanged==" + provider);
  }

 };
}

class LocactionM extends LocationManagerProxy {

 public LocactionM(Context arg0, String arg1) {
  super(arg0, arg1);
  // TODO Auto-generated constructor stub
 }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值