当前位置:   article > 正文

百度定位+精确定位+模糊城市定位_飞书定位应该精确还是模糊

飞书定位应该精确还是模糊

百度定位相信大家都会使用,作为一个一年经验的安卓经验的新人,我也就不多说什么了.今天要给大家带来的是一个模糊定位,一个小小的需求,就是根据自己的定位地点的经纬度,解析旁边城市的经纬度,得到一个距离最近的城市.详细的和大家描述一下.
比如点 深圳(x1,y1)–>(地点名称)(纬度,经度)
北京(x2,y2)–>(地点名称)(纬度,经度)
如果我现在的定位地点是广州(x3,y3).
那么广州和深圳的距离是[(x3-x1)(x3-x1)]开方,同理广州和北京的距离是[(x3-x2)(x3-x2)]开方.比较两段距离的长度,判断自己离哪个城市更近,则选择哪个城市.
需求就是这么简单.
这里写图片描述
这里![

一下是源码和包

<MainActivity>

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.TextView;
import android.widget.Toast;

import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;

public class MainActivity extends Activity {
   

    private GridView gridview;
    private List<Map<String, String>>list = new ArrayList<Map<String,String>>();

    private TextView city_tv;

    private String back_city;

    private List<Map<String, String>>list_hz = new ArrayList<Map<String,String>>();

    /******************************************定位代码的实现*************************/
    private String TAG = "MainActivity";
    /** 定位成功标识 */
    private final int LOCATION_SUCCESS = 1;
    /** 定位失败标识 */
    private final int LOCATION_ERROR = 0;
    /** 百度定位器 */
    private LocationClient mLocClient;
    /** 延迟发送,设置成全局,用于解决快速按按钮导致的开启了多个线程 */
    private Runnable mRunable;
    /******************************************定位代码的实现*************************/

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        back_city = "深圳";

        /******************************************定位代码的实现*************************/
        initData();
        /******************************************定位代码的实现*************************/

        //初始化id
        setViews();

        //设置城市列表属性
        setGridView();

        //设置国家城市经纬度
        setHZ();


        /******************************************定位代码的实现*************************/
        mRunable = new Runnable() {

            @Override
            public void run() {
                mLocClient.start();// 开始定位
            }
        };
        handler.postDelayed(mRunable,0);
        /******************************************定位代码的实现*************************/
        city_tv.setText("正在定位...");

    }

    //初始化城市坐标点数据
    private void setHZ() {
        list_hz = new ArrayList<Map<String,String>>();
        String str[] = {
  "北京","上海","广州",
                "深圳","杭州","天津",
                "苏州","南京","成都",
                "重庆","西安","武汉",
                "沈阳","宁波","长沙",
                "济南","郑州","无锡",
                "青岛","哈尔滨","温州",
                "福州","香港"};
        String xx[] = {
  "39.26","30.4","23.11",
                "22.37","30.3","38.33",
                "31.3","32.03","30.67",
                "29.5","34.15","29.58",
                "41.8","28.51","27.51",
                "36.40","34.16","31.7",
                "35.35","44.04","27.03",
                "26.08","22.15"};
        String yy[] = {
  "115.25","120.51","113.27",
                "114.04","120.2","116.42",
                "120.6","118.46","104.06",
                "106.5","108.56","113.41",
                "123.4","120.55","111.53",
                "117","112.42","119.33",
                "119.30","125.42","119.37",
                "119.28","114.15"};

        for (int i = 0; i < str.length; i++) {
            Map<String, String>map = new HashMap<String, String>();
            map.put("address", str[i]);
            map.put("weidu", xx[i]);
            map.put("jingdu", yy[i]);
            list_hz.add(map);
        }



    }

    /******************************************定位代码的实现*************************/
    private void initData() {
        Log.i("TGA", "===initData()");
        /* 初始化定位信息 */
        mLocClient = new LocationClient(this);// 创建定位器
        // mLocClient.setAK("64qAcRkfBfe6Rh6c37tfEAi8");// 设置Key值
        mLocClient.registerLocationListener(mLocationListener);

        LocationClientOption mLocOption = 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/290452
推荐阅读
相关标签
  

闽ICP备14008679号