机器人 - 如何获得当前位置的经纬度经纬度、当前位置、机器人、如何获得

由网友(余生颓废)分享简介:我用这code,以获得当前位置的经度和纬度,但我没有得到当前位置的纬度和longitude.anyone知道俺们更新在这里,感谢包com.ram.currentlocation;进口android.app.Activity;进口android.content.Context;进口android.location.L...

我用这code,以获得当前位置的经度和纬度,但我没有得到当前位置的纬度和longitude.anyone知道俺们更新在这里,

感谢

 包com.ram.currentlocation;

进口android.app.Activity;
进口android.content.Context;
进口android.location.Location;
进口android.location.LocationListener;
进口android.location.LocationManager;
进口android.os.Bundle;
进口android.widget.Toast;

公共类Location_Gps扩展活动
{

    / **第一次创建活动时调用。 * /
    @覆盖
    公共无效的onCreate(包savedInstanceState)
    {
      super.onCreate(savedInstanceState);
      的setContentView(R.layout.main);

      / *使用LocationManager类获取GPS位置* /
      LocationManager mlocManager =(LocationManager)getSystemService(Context.LOCATION_SERVICE);

      LocationListener的mlocListener =新MyLocationListener();
      mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,mlocListener);
    }

    / *类我的位置监听* /
    公共类MyLocationListener实现LocationListener的
    {

      @覆盖
      公共无效onLocationChanged(位置LOC)
      {

        loc.getLatitude();
        loc.getLongitude();

        字符串文本=我目前的位置是:+
        Latitud =+ loc.getLatitude()+
        Longitud =+ loc.getLongitude();

        Toast.makeText(getApplicationContext(),文本,Toast.LENGTH_SHORT).show();
      }

      @覆盖
      公共无效onProviderDisabled(字符串提供商)
      {
        Toast.makeText(getApplicationContext(),全球定位系统已禁用,Toast.LENGTH_SHORT).show();
      }

      @覆盖
      公共无效onProviderEnabled(字符串提供商)
      {
        Toast.makeText(getApplicationContext(),GPS功能的,Toast.LENGTH_SHORT).show();
      }

      @覆盖
      公共无效onStatusChanged(字符串商,INT地位,捆绑演员)
      {

      }
    }
}
 

我使用清单code在这里,

 <使用-权限的Andr​​oid:名称=android.permission.ACCESS_FINE_LOCATION/>
<使用-权限的Andr​​oid:名称=android.permission.ACCESS_CORSE_LOCATION/>
 

解决方案

您的清单文件中的错误。正确的是:

 <使用-权限的Andr​​oid:名称=android.permission.ACCESS_COARSE_LOCATION/>
 
一文读懂 移动机器人5种常用定位技术

I am using this code to get current location latitude and longitude but i am not getting current location latitude and longitude.anyone know the ans update here,

thanks

package com.ram.currentlocation;

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

public class Location_Gps extends Activity
{

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);

      /* Use the LocationManager class to obtain GPS locations */
      LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);

      LocationListener mlocListener = new MyLocationListener();
      mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
    }

    /* Class My Location Listener */
    public class MyLocationListener implements LocationListener
    {

      @Override
      public void onLocationChanged(Location loc)
      {

        loc.getLatitude();
        loc.getLongitude();

        String Text = "My current location is: " +
        "Latitud = " + loc.getLatitude() +
        "Longitud = " + loc.getLongitude();

        Toast.makeText( getApplicationContext(), Text, Toast.LENGTH_SHORT).show();
      }

      @Override
      public void onProviderDisabled(String provider)
      {
        Toast.makeText( getApplicationContext(), "Gps Disabled", Toast.LENGTH_SHORT ).show();
      }

      @Override
      public void onProviderEnabled(String provider)
      {
        Toast.makeText( getApplicationContext(), "Gps Enabled", Toast.LENGTH_SHORT).show();
      }

      @Override
      public void onStatusChanged(String provider, int status, Bundle extras)
      {

      }
    }
}

i am using manifest code here,

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_CORSE_LOCATION"/>

解决方案

You have a mistake in your manifest file. Correct one is:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

阅读全文

相关推荐

最新文章