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
Win a copy of
Darcy DeClute's Scrum Master Certification Guide: The Definitive Resource for Passing the CSM and PSM Exams
this week in the
Agile and Other Processes
forum!
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
Devaka Cooray
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Jeanne Boyarsky
Tim Cooke
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Tim Moores
Mikalai Zaikin
Carey Brown
Bartenders:
Forum:
Android
it doesn't shows location details
shawn peter
Ranch Hand
Posts: 1325
1
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
this is my code.
but it doesn't sow me thw current longitude & latitudes
package com.android.aruna; import java.io.IOException; import java.util.List; import android.app.Activity; import android.content.Context; 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 LocationFinder extends Activity implements LocationListener{ public LocationManager locationmanager; public 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.locationDetailTxtView); Criteria cri=new Criteria(); cri.setPowerRequirement(Criteria.POWER_LOW); cri.setAccuracy(Criteria.ACCURACY_FINE); locationmanager=(LocationManager) getSystemService(Context.LOCATION_SERVICE); String bestProvider=locationmanager.getBestProvider(cri, false); Location lastKnownLocation=locationmanager.getLastKnownLocation(bestProvider); if(lastKnownLocation!=null){ locationDetails="latitude"+lastKnownLocation.getLatitude()+"longitute"+lastKnownLocation.getLongitude(); locationDetailsTextView.setText(locationDetails); } } @Override public void onLocationChanged(Location location) { TextView locationDetailsTextView=(TextView)findViewById(R.id.locationDetailTxtView); locationDetails="Last known location;-----latitude:" +location.getLatitude()+"longitude:" +location.getLongitude(); Geocoder geo=new Geocoder(this); try { List<Address> address=geo.getFromLocation(location.getLatitude(), location.getLongitude(), 1); for(Address addresses:address){ locationDetails+="Address is "+ addresses.getAddressLine(0)+""+addresses.getCountryName(); } locationDetailsTextView.setText(locationDetails); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } @Override public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } @Override public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } @Override public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } }
Tim Moores
Saloon Keeper
Posts: 7549
176
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Is there a call to LocationManager.requestLocationUpdates somewhere ... ?
shawn peter
Ranch Hand
Posts: 1325
1
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
thanks.i change the class to below
package com.android.aruna; import java.io.IOException; import java.util.List; import android.app.Activity; import android.content.Context; 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 LocationFinder extends Activity implements LocationListener{ public LocationManager locationmanager; public 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.locationDetailTxtView); Criteria cri=new Criteria(); cri.setPowerRequirement(Criteria.POWER_LOW); cri.setAccuracy(Criteria.ACCURACY_FINE); locationmanager=(LocationManager) getSystemService(Context.LOCATION_SERVICE); String bestProvider=locationmanager.getBestProvider(cri, false); Location lastKnownLocation=locationmanager.getLastKnownLocation(bestProvider); if(lastKnownLocation!=null){ locationDetails="latitude"+lastKnownLocation.getLatitude()+"longitute"+lastKnownLocation.getLongitude(); locationDetailsTextView.setText(locationDetails); locationmanager.requestLocationUpdates(bestProvider, 500, 0.2f, this); } } @Override public void onLocationChanged(Location location) { TextView locationDetailsTextView=(TextView)findViewById(R.id.locationDetailTxtView); locationDetails="Last known location;-----latitude:" +location.getLatitude()+"longitude:" +location.getLongitude(); Geocoder geo=new Geocoder(this); try { List<Address> address=geo.getFromLocation(location.getLatitude(), location.getLongitude(), 1); for(Address addresses:address){ locationDetails+="Address is "+ addresses.getAddressLine(0)+""+addresses.getCountryName(); } locationDetailsTextView.setText(locationDetails); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } @Override public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } @Override public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } @Override public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } }
still it doesn't display anything.i moved more than 10 meters with my phone.But nothing shows
shawn peter
Ranch Hand
Posts: 1325
1
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
this is my main.xml file
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <LinearLayout android:layout_height="wrap_content" android:id="@+id/linearLayout1" android:layout_width="match_parent"> <Button android:layout_height="wrap_content" android:id="@+id/button" android:layout_width="wrap_content" android:text="@string/button"></Button> </LinearLayout> <LinearLayout android:layout_height="wrap_content" android:orientation="vertical" android:id="@+id/linearLayout1" android:layout_width="match_parent"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" android:id="@+id/locationDetailTxtView"/> </LinearLayout>
this is my manifest file
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.aruna" android:versionCode="1" android:versionName="1.0"> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission> <uses-permission android:name="android.permission.INTERNET" /> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".LocationFinder" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
it shows me the button. then below the button it show below text
" Hello world , Location finder
other than that there is nothing ?
Tim Moores
Saloon Keeper
Posts: 7549
176
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Why is requestLocationUpdates only being called if there is a last known location? Have you done logging to determine whether it *is* being called? Which provider is selected as "bestProvider"?
shawn peter
Ranch Hand
Posts: 1325
1
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I change the code as belows
if(lastKnownLocation!=null){ locationDetails="latitude"+lastKnownLocation.getLatitude()+"longitute"+lastKnownLocation.getLongitude(); locationDetailsTextView.setText(locationDetails); } locationmanager.requestLocationUpdates(bestProvider, 500, 0.2f, this);
but still same.nothing display?
shawn peter
Ranch Hand
Posts: 1325
1
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I try to debug this code.But it never gone to onLocationChanged method.I don't know why ?
shawn peter
Ranch Hand
Posts: 1325
1
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Iam using android 2.3 os phone .Can it be a problem?
Look! I laid an egg! Why does it smell like that? Tiny ad, does this smell weird to you?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
it doesn't give me the country name
it doesn't change the longitude & latitude
It prints me pointer repeatedly
how to add a google search option
street view & satilite view is not working
More...