Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Android
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Android
it doesn't change the longitude & latitude
shawn peter
Ranch Hand
Posts: 1325
1
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
This is the my class
package com.visini.android; import java.util.List; import android.app.Activity; import android.location.Address; import android.location.Criteria; import android.location.Geocoder; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.widget.TextView; public class LocationActivity extends Activity implements LocationListener { private LocationManager locationManager; private String locationdetails; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TextView locationdetailstextview = (TextView)findViewById(R.id.locationDetailstextView); locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); //Get the best provider for the criteria Criteria criteria = new Criteria(); criteria.setPowerRequirement(Criteria.POWER_LOW); criteria.setAccuracy(Criteria.ACCURACY_COARSE); String bestprovider = locationManager.getBestProvider(criteria,false); Location lastknownlocation = locationManager.getLastKnownLocation(bestprovider); //Location lastknownlocation = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER); if (lastknownlocation != null){ locationdetails = "Last Know Location:----- Latitude: "+lastknownlocation.getLatitude() +"Longitude :"+lastknownlocation.getLongitude(); locationdetailstextview.setText(locationdetails); } locationManager.requestLocationUpdates(bestprovider,5000, 0.2f, this); // locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,5000, 0.2f, this); } @Override public void onLocationChanged(Location location) { try{ // TODO Auto-generated method stub TextView locationdetailstextview = (TextView)findViewById(R.id.locationDetailstextView); locationdetails += "\n Current Location:----- Latitude: "+location.getLatitude() +"Longitude :"+location.getLongitude(); locationdetailstextview.setText(locationdetails); //get the address using google map Geocoder geocoder = new Geocoder(this); List<Address> addresses = geocoder.getFromLocation(location.getLatitude(),location.getLongitude(),1); for (Address address: addresses){ locationdetails += "Address is "+address.getAddressLine(0)+" ,"+address.getCountryName(); } } catch(Exception e){ System.out.println(e.toString()); } } @Override public void onProviderDisabled(String arg0) { // TODO Auto-generated method stub } @Override public void onProviderEnabled(String arg0) { // TODO Auto-generated method stub } @Override public void onStatusChanged(String arg0, int arg1, Bundle arg2) { // TODO Auto-generated method stub } }
this is working fine .it shows the longitude & latitude.
1)But when i move the phone it doen't change the values.
2)Also it doen't show me the current address or country /
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
it doesn't give me the country name
it doesn't shows location details
It prints me pointer repeatedly
how to add a google search option
street view & satilite view is not working
More...