高德地图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
 }

}

你可能感兴趣的:(android,定位,gps,高德)