Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to get longitude and latitude on my android device
    primarykey
    data
    text
    <p>I have an application that displays the GPS longitude and latitude. It works if i use the LocationManager.NETWORK_PROVIDER it display the longitude and latitude of the network. But when i use LocationManager.GPS_PROVIDER it does not display anything. But when i use google maps it can point where i am. What does google maps do to get my location? I need to get the Longitude and Latitude of my device.</p> <p>Here is my code</p> <pre><code>import android.location.LocationManager; import android.location.Location; import android.location.LocationListener; import android.os.Bundle; import android.app.Activity; import android.content.Context; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; public class Main extends Activity implements OnClickListener{ double glat; double glng; LocationListener glocListener; TextView longitudetv; TextView latitudetv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TextView tv = (TextView) findViewById(R.id.mytextview); tv.setVisibility(View.GONE); longitudetv = (TextView) findViewById(R.id.textView3); longitudetv.setVisibility(View.GONE); latitudetv = (TextView) findViewById(R.id.textView4); latitudetv.setVisibility(View.GONE); Button b = (Button) findViewById(R.id.button1); b.setOnClickListener(this); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } //This is for Lat lng which is determine by your device GPS public class MyLocationListenerGPS implements LocationListener { @Override public void onLocationChanged(Location loc) { glat = loc.getLatitude(); glng = loc.getLongitude(); //Setting the GPS Lat, Lng into the textView longitudetv.setText("" + glng); latitudetv.setText("" + glat); } @Override public void onProviderDisabled(String provider) { } @Override public void onProviderEnabled(String provider) { } @Override public void onStatusChanged(String provider, int status, Bundle extras) { } } @Override public void onClick(View v) { // TODO Auto-generated method stub if(v.getId()==R.id.button1){ LocationManager locman = (LocationManager) getSystemService(Context.LOCATION_SERVICE); TextView tv = (TextView) findViewById(R.id.mytextview); tv.setVisibility(View.VISIBLE); if(locman.isProviderEnabled(LocationManager.GPS_PROVIDER)){ tv.setText("Started!"); latitudetv.setVisibility(View.VISIBLE); longitudetv.setVisibility(View.VISIBLE); locman = (LocationManager)getSystemService(Context.LOCATION_SERVICE); glocListener = new MyLocationListenerGPS(); locman.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000 * 1, // 1 Sec 0, // 0 meter glocListener); } else{ tv.setText("There is no GPS Connection"); Toast.makeText( getApplicationContext(), "GPS is Disabled.Please enable GPS", Toast.LENGTH_SHORT ).show(); } } } } </code></pre> <p>My manifest file</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.willardcuizon.adaptivedgps" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="10" android:targetSdkVersion="17" /&gt; &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/&gt; &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt; &lt;uses-permission android:name="android.permission.INTERNET" /&gt; &lt;application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" android:debuggable="false"&gt; &lt;activity android:name="com.willardcuizon.adaptivedgps.Main" android:label="@string/app_name" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;/application&gt; </code></pre> <p></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload