2013-02-10 76 views
1

你好我很新到Android .. 我正在做哪些需要精确(约50米精度上可接受的)用户位置.. 我使用的LocationManager和LocationListener的一个应用程序.. 每当我启动应用程序,我需要返回用户位置。问题是locationlistener中的onlocationchanged方法仅在它们更改时返回经度经度。 我如何获取用户位置?如何使用onlocationchanged方法在LocationListener的

locmgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, loclist_netwk); 这就是我如何调用我已经实现了locationlistener的类。

`

package com.example.gpsmanager; 

import android.app.Activity; 
import android.content.Context; 
import android.location.Location; 
import android.location.LocationListener; 
import android.os.Bundle; 
import android.widget.TextView; 
import android.widget.Toast; 

public class MyLocationListener extends Activity implements LocationListener 
{ 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.mylocation_layout); 
    } 
    @Override 

    public void onLocationChanged(Location loc) { 
     // TODO Auto-generated method stub 
     loc.getLatitude(); 
     loc.getLongitude(); 
     String text="my current location is"+"lat: "+loc.getLatitude()+"long: "+loc.getLongitude(); 
     //TextView text1=(TextView) findViewById(R.id.textView1); 
     //text1.setText(text+""); 
     Toast.makeText(MyLocationListener.this, text, Toast.LENGTH_LONG).show();   
    } 

    @Override 
    public void onProviderDisabled(String arg0) { 
     // TODO Auto-generated method stub 
     String text="GPS Provider not availabe"; 
    } 

    @Override 
    public void onProviderEnabled(String arg0) { 
     // TODO Auto-generated method stub 
     String text="GPS Provider availabe"; 
    } 

    @Override 
    public void onStatusChanged(String arg0, int arg1, Bundle arg2) { 
     // TODO Auto-generated method stub 

    } 

} 

` pllzz plzz帮助家伙... .. thankss

+0

''getLastKnownLocation的'LocationManager'(字符串提供商)可能有帮助。 – Geros 2013-02-10 07:00:42

+0

getLastKnownLocation给出最后已知用户的位置不是当前的..我猜... – tanmayub 2013-02-10 07:26:49

+0

看这个旧的主题: [怎么办-I-GET-的电流-GPS定位,编程功能于安卓] [1] 和 [什么,是最简单和最稳健的路到得到-的用户,当前定位功能于一] [2] [1]:http://stackoverflow.com/questions/1513485/how-do-i-get-the-current-gps-location-programmatic ally-in-android [2]:http://stackoverflow.com/questions/3145089/what-is-the-simplest-and-most-robust-way-to-get-the-users-current-location -in-a/ – Palejandro 2013-02-10 08:23:06

回答

0
 For user location you can use Reverse Geocoding 

     For it u have to send only lat,long. 
Code is below:- 

public String getAddress(double lat, double lng,Context mContext) { 
     Geocoder geocoder = new Geocoder(mContext, Locale.getDefault()); 
     try { 
      List<Address> addresses = geocoder.getFromLocation(lat, lng,1); 
      String add=""; 
      for(int i=0;i<addresses.size();i++){ 
      Address obj = addresses.get(i); 
      //String = obj.getAddressLine(i); 
      add = add+obj.getAddressLine(i)+","+obj.getLocality()+","+obj.getAdminArea()+","+obj.getCountryName(); 

      Log.v("IGA", "\n"+"Address " + add); 

      } 
      return add; 
      } catch (IOException e) { 
      e.printStackTrace(); 
      Toast.makeText(mContext, e.getMessage(), Toast.LENGTH_SHORT).show(); 
      return null; 
     } 
    } 
+0

不好.. !! 我需要找到用户的GPS位置不是地址...我不想用户位置与OnLocationChanged ...我想要用户位置,只要用户登录到应用程序... – tanmayub 2013-02-12 06:11:18

相关问题