Android不开gps怎样定位

ghliusimple 2016-07-21 12:12:54
百度外卖和美团一些应用没有打开gps也能获取当前位置,请问是怎么做到的?具体点,不要说什么基站定位,怎么实现的?
...全文
294 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ink_s 2016-07-21
  • 打赏
  • 举报
回复
我以前用过高德地图,他的demo里就有选择定位方式,用的时候只需要选择就行了,具体人家是怎么得到数据的,我们不需用去管。
ink_s 2016-07-21
  • 打赏
  • 举报
回复
基站定位一般有几种,第一种是利用手机附近的三个基站进行三角定位,由于每个基站的位置是固定的,利用电磁波在这三个基站间中转所需要时间来算出手机所在的坐标;第二种则是利用获取最近的基站的信息,其中包括基站 id,location area code、mobile country code、mobile network code和信号强度,将这些数据发送到google的定位web服务里,就能拿到当前所在的位置信息,误差一般在几十米到几百米之内。
ink_s 2016-07-21
  • 打赏
  • 举报
回复
WiFi定位 先获取WiFi热点的地址:
public classWiFiInfoManager implements Serializable {
          private static final long serialVersionUID= -4582739827003032383L;
          private Context context;
          public WiFiInfoManager(Context context) {
            super();
            this.context = context;
          }
          public WifiInfo getWifiInfo() {
            WifiManager manager = (WifiManager)context
               .getSystemService(Context.WIFI_SERVICE);
            WifiInfo info = new WifiInfo();
            info.mac =manager.getConnectionInfo().getBSSID();
            Log.i( TAG , WIFI MACis: + info.mac);
            return info;
          }
          public class WifiInfo {
            public String mac;
            public WifiInfo() {
              super();
            }
          }
        }
再把地址发送到服务器,返回具体地址数据:
public staticLocation getWIFILocation(WifiInfo wifi) {
            if (wifi == null) {
              Log.i( TAG , wifiis null. );
              return null;
            }
            DefaultHttpClient client = newDefaultHttpClient();
            HttpPost post = new HttpPost( http://www.google.com/loc/json );
            JSONObject holder = new JSONObject();
            try {
              holder.put( version , 1.1.0 );
              holder.put( host , maps.google.com );
              JSONObject data;
              JSONArray array = new JSONArray();
              if (wifi.mac != null  wifi.mac.trim().length()  0) {
                data = new JSONObject();
               data.put( mac_address , wifi.mac);
               data.put( signal_strength , 8);
                data.put( age , 0);
                array.put(data);
              }
              holder.put( wifi_towers ,array);
              Log.i( TAG , request json: + holder.toString());
              StringEntity se = newStringEntity(holder.toString());
              post.setEntity(se);
              HttpResponse resp =client.execute(post);
              int state =resp.getStatusLine().getStatusCode();
              if (state == HttpStatus.SC_OK) {
                HttpEntity entity =resp.getEntity();
                if (entity != null) {
                  BufferedReader br = newBufferedReader(
                      newInputStreamReader(entity.getContent()));
                  StringBuffer sb = newStringBuffer();
                  String resute = ;
                  while ((resute =br.readLine()) != null) {
                    sb.append(resute);
                  }
                  br.close();
                  Log.i( TAG , response json: + sb.toString());
                  data = newJSONObject(sb.toString());
                  data = (JSONObject)data.get( location );
                  Location loc = newLocation(
                     android.location.LocationManager.NETWORK_PROVIDER);
                  loc.setLatitude((Double)data.get( latitude ));
                  loc.setLongitude((Double)data.get( longitude ));
                 loc.setAccuracy(Float.parseFloat(data.get( accuracy )
                      .toString()));
                  loc.setTime(System.currentTimeMillis());
                  return loc;
                } else {
                  return null;
                }
              } else {
                Log.v( TAG , state + );
                return null;
              }
            } catch (Exception e) {
              Log.e( TAG ,e.getMessage());
              return null;
            }
          }
放狼的爷们 2016-07-21
  • 打赏
  • 举报
回复
网络定位,具体方法看百度地图的文档啊~
ink_s 2016-07-21
  • 打赏
  • 举报
回复
WIFI ,GPS ,3G 都可以定位

80,471

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧