title: What is the simplest way to get the user's longitude and latitude in Android ? Even without using listener?
body: <p>My app just need to know user's country, and my app doesn't care where user moves.</p>
  
  <p>All I want to know is :
  When user start app, app will send user's approximately location(latitude and longitude) to server.</p>
  
  <p>Here is my code with error. I try to send a string to getlocation function, and I hope it can return original string with adding latitude and longitude information.</p>
  
  <pre><code>private String getlocation (String url){
      LocationManager status = (LocationManager) (this.getSystemService(Context.LOCATION_SERVICE));
      if (status.isProviderEnabled(LocationManager.GPS_PROVIDER) || status.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
          Log.v("print","enable to locate");
      } else {
          Log.v("print","fail to locate");
      }
      Location location = status.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);  
      if(location!=null){ 
        Log.v("print","succed!!!@@");
        Double longitude = location.getLongitude();
        String loc=Double.toString(longitude);
        url=url+loc;
      }
      else{
          Log.v("print","location return null");
       }
      return url;
  }
  </code></pre>
  
  <p>I use network_provider, and it always print "enable to locate", then print "location return null"</p>
  
  <p>So what's wrong with my code that my location always return null.
  I use AVD manerger, and I also try GPS_PROVIDER. I use Emulator control to send Decimal on location control. It doesn't work ,too.</p>
  
  <p>By the way, I set network and GPS permission,too.</p>
  
  <p>So much thanks for help!</p>