2016-12-01 21 views

回答

1

您可以在任何國家使用GPS /網絡定位服務。然後上傳用戶定位到您的服務器和可以通過緯度識別用戶的國家和緯度

LocationListener locationListener = new LocationListener() { 


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

     } 


     @Override 
     public void onProviderEnabled(String provider) { 

     } 


     @Override 
     public void onProviderDisabled(String provider) { 

     } 


     @Override 
     public void onLocationChanged(Location location) { 
      if (location != null) { 

       longitude = location.getLongitude(); 
       latitude = location.getLatitude(); 
      } 
     } 
    }; 

    try { 
     Location location = null; 

     LocationManager locationManager = (LocationManager) context 
       .getSystemService(Context.LOCATION_SERVICE); 

     if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { 
      location = locationManager 
        .getLastKnownLocation(LocationManager.GPS_PROVIDER); 

     } else if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { 
      location = locationManager 
        .getLastKnownLocation(LocationManager.NETWORK_PROVIDER); 
     } 
     if (locationManager.getAllProviders().contains(LocationManager.NETWORK_PROVIDER)) { 
      locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 0, locationListener); 
     } 

    } catch (Exception e) { 

     e.printStackTrace(); 
    } 
+0

但你應該告訴用戶你上傳用戶位置到服務器。 – Yat3s

相關問題