机器人 - 如何获得当前位置的经纬度 [英] android - how to get current location latitude and longitude

查看:199
本文介绍了机器人 - 如何获得当前位置的经纬度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用这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/>
 

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"/>

这篇关于机器人 - 如何获得当前位置的经纬度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆