2016-03-22 2 views
-4
@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     txt = (TextView) findViewById(R.id.txt); 


    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { 
     // TODO: Consider calling 
     // ActivityCompat#requestPermissions 
     // here to request the missing permissions, and then overriding 
     // public void onRequestPermissionsResult(int requestCode, String[] permissions, 
     //           int[] grantResults) 
     // to handle the case where the user grants the permission. See the documentation 
     // for ActivityCompat#requestPermissions for more details. 
     return; 
    } 
    locationManager.requestLocationUpdates(locationManager.NETWORK_PROVIDER, 0, 0, this); 
    locationManager.requestLocationUpdates(locationManager.GPS_PROVIDER, 0, 0, this); 
} 


@Override 
public void onLocationChanged(Location location) { 
    txt=(TextView)findViewById(R.id.txt); 
    txt.setText("longtude is :" + location.getLongitude() + "latitude is :" + location.getLatitude()); 
} 

@Override 
public void onStatusChanged(String provider, int status, Bundle extras) { 

} 

@Override 
public void onProviderEnabled(String provider) { 

} 

@Override 
public void onProviderDisabled(String provider) { 

} 

答えて

0

チェックが行

Location l; 
String provider; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    txt = (TextView) findViewById(R.id.txt); 


locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { 
    // TODO: Consider calling 
    // ActivityCompat#requestPermissions 
    // here to request the missing permissions, and then overriding 
    // public void onRequestPermissionsResult(int requestCode, String[] permissions, 
    //           int[] grantResults) 
    // to handle the case where the user grants the permission. See the documentation 
    // for ActivityCompat#requestPermissions for more details. 
    return; 
} 
locationManager.requestLocationUpdates(locationManager.NETWORK_PROVIDER, 0, 0, this); 
locationManager.requestLocationUpdates(locationManager.GPS_PROVIDER, 0, 0, this); 
Criteria c=new Criteria(); 
provider=locationManager.getBestProvider(c, false); 
l=locationManager.getLastKnownLocation(provider); 
if(l!=null) 
{ 
//get latitude and longitude of the location 
double lng=l.getLongitude(); 
double lat=l.getLatitude(); 
//display on text view 
txt.setText(lng+ ""+ lat); 
} 
else 
{ 
txt.setText("No Provider"); 
} 
} 

@Override 
public void onLocationChanged(Location arg0) 
{ 
double lng=l.getLongitude(); 
double lat=l.getLatitude(); 
txt.setText(lng+ ""+ lat); 
} 
+0

それは私の作品のおかげで、しかしlongtudeと緯度の下に追加グーグルマップに再びそれを使用する – user3605952

関連する問題