当前位置:编程学习 > 网站相关 >>

google maps开发当前位置定位问题!

public class MallFinderActivity extends MapActivity implements LocationListener {
    /** Called when the activity is first created. */
   private LocationManager locationManager;
   private GeoPoint currentLocation;
  
  public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
     MapView   mapView;
     MapController mapController;
        setContentView(R.layout.main);
        mapView = (MapView)findViewById(R.id.mapView); 
        mapView.setBuiltInZoomControls(true); 
        mapView.setSatellite(false); 
        mapView.setStreetView(true); 
        mapController = mapView.getController(); 
        mapController.setZoom(13);
    getLastLocation(); 
    animateToCurrentLocation(); 
}
   
  protected boolean isRouteDisplayed(){
      return false;
    }
  public void getLastLocation(){ 
    String provider = getBestProvider(); 
    currentLocation = locationManager.getLastKnownLocation(provider); 
    if(currentLocation != null){ 
        setCurrentLocation(currentLocation); 
    } 
    else
    { 
        Toast.makeText(this, "Location not yet acquired", Toast.LENGTH_LONG).show(); 
    } 

  
public void animateToCurrentLocation(){ 
    if(currentPoint!=null){ 
        MapController.animateTo(currentPoint); 
    } 

  
public String getBestProvider(){ 
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    Criteria criteria = new Criteria(); 
    criteria.setPowerRequirement(Criteria.NO_REQUIREMENT); 
    criteria.setAccuracy(Criteria.NO_REQUIREMENT); 
    String bestProvider = locationManager.getBestProvider(criteria, true); 
    return bestProvider; 

  
public void setCurrentLocation(Location location){ 
    int currLatitude = (int) (location.getLatitude()*1E6); 
    int currLongitude = (int) (location.getLongitude()*1E6); 
    currentLocation = new GeoPoint(currLatitude,currLongitude); 
  
    currentLocation = new Location(""); 
    currentLocation.setLatitude(currentPoint.getLatitudeE6() / 1e6); 
    currentLocation.setLongitude(currentPoint.getLongitudeE6() / 1e6); 
}
 
这是找的源代码!有几个地方比较模糊! Google Maps --------------------编程问答-------------------- 红的地方处理我看不懂!! MapController.animateTo(currentPoint); 这个方法的参数用法比较模糊! --------------------编程问答-------------------- 做个google maps的来帮帮忙! --------------------编程问答-------------------- 大神来啊!!
补充:云计算 ,  OpenAPI
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,