2011-03-09 9 views

答えて

1

試してみる

public class MyLocationOnMap extends MapActivity { 

     private LocationManager hdLocMgr; 
     private String hdLocProvider; 


     onCreate(...) { 
      : 
     Criteria hdCrit = new Criteria(); 
     hdCrit.setAccuracy(Criteria.ACCURACY_COARSE); 
     hdCrit.setAltitudeRequired(false); 
     hdCrit.setBearingRequired(false); 
     hdCrit.setCostAllowed(true); 
     hdCrit.setPowerRequirement(Criteria.POWER_LOW); 

     hdLocMgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 

     hdLocProvider = hdLocMgr.getBestProvider(hdCrit, true); 

     Location location = hdLocMgr.getLastKnownLocation(hdLocProvider); 

     Double dlat = location.getLatitude(); 
     Double dlon = location.getLongitude(); 
       : 
     } 

} 
+0

場所がNULL取得のコメントを読まずにゴミ答えを与えることのように思える:( – indira

+0

私はエミュレータで現在位置を得ることができますか? – indira

+0

はい、http://developer.android.com/guide/developing/debugging/ddms.htmlにアクセスし、「電話の場所を設定する」を検索することができます。 – Abhi

1

、次のことができます。条件の詳細については

Criteria criteria = new Criteria(); 
criteria.setAccuracy(Criteria.ACCURACY_COARSE); 
criteria.setPowerRequirement(Criteria.POWER_LOW); 
criteria.setAltitudeRequired(false); 
criteria.setBearingRequired(false); 
criteria.setSpeedRequired(false); 
Criteria.setCostAllowed(true); 

String bestProvider = locationManager.getBestProvider(criteria, true); 

Location location = 
     locationManager.getLastKnownLocation(bestProvider); 
    updateWithNewLocation(location); 

    locationManager.requestLocationUpdates(bestProvider , 2000, 10, 
      locationListener); 

を使用した場所のプロバイダを見つけるあなたの現在の場所

選択するロケーションプロバイダ

String providerName = LocationManager.GPS_PROVIDER; 
LocationProvider gpsProvider; 
gpsProvider = locationManager.getProvider(providerName); 

を入手訪問:http://developer.android.com/reference/android/location/LocationManager.html

+0

私はあなたが適切に質問を読んhaventは考える – ingsaurabh

+1

葉、馬鹿のたくさんでも – ericlee