Search in sources :

Example 1 with SinaLocationMap

use of org.aisen.weibo.sina.sinasdk.bean.SinaLocationMap in project AisenWeiBo by wangdan.

the class SinaSDK method locationMobileGetLocation.

/**
	 * 根据移动基站WIFI等数据获取当前位置信息
	 * 
	 * @return
	 * @throws TaskException
	 */
public SinaLocationMap locationMobileGetLocation() throws TaskException {
    Map<String, Object> requestMap = new HashMap<String, Object>();
    // 请求版本信息
    requestMap.put("version", "2.0");
    // 请求地址信息
    requestMap.put("host", "api.weibo.com");
    // 请求类型
    requestMap.put("radio_type", "gsm");
    // 是否需要返回详细地址,可选,默认:false
    requestMap.put("request_address", "true");
    // 返回坐标是否偏移处理,偏移后坐标适合在新浪地图上使用(http://map.sina.com.cn),
    // 不适用于百度地图(各地图偏移量不同,请谨慎处理);可选,默认:false
    requestMap.put("decode_pos", "true");
    TelephonyManager mTelNet = (TelephonyManager) GlobalContext.getInstance().getSystemService(Context.TELEPHONY_SERVICE);
    GsmCellLocation location = null;
    if (mTelNet != null)
        location = (GsmCellLocation) mTelNet.getCellLocation();
    if (location != null) {
        String operator = mTelNet.getNetworkOperator();
        int mcc = Integer.parseInt(operator.substring(0, 3));
        int mnc = Integer.parseInt(operator.substring(3));
        List<NeighboringCellInfo> cellInfoList = mTelNet.getNeighboringCellInfo();
        ArrayList<Map<String, Object>> cellMapList = new ArrayList<Map<String, Object>>();
        for (NeighboringCellInfo cellInfo : cellInfoList) {
            // 基站信息
            Map<String, Object> cellMap = new HashMap<String, Object>();
            // 基站号
            cellMap.put("cell_id", location.getCid());
            // 小区号
            cellMap.put("location_area_code", cellInfo.getLac());
            // 地区代码
            cellMap.put("mobile_country_code", mcc);
            // 运营商号
            cellMap.put("mobile_network_code", mnc);
            // 信号强度
            cellMap.put("signal_strength", cellInfo.getRssi());
            cellMapList.add(cellMap);
        }
        if (cellMapList.size() > 0)
            requestMap.put("cell_towers", cellMapList);
    }
    WifiManager wm = (WifiManager) GlobalContext.getInstance().getSystemService(Context.WIFI_SERVICE);
    List<ScanResult> scanResultList = wm.getScanResults();
    if (scanResultList != null && scanResultList.size() > 0) {
        ArrayList<Map<String, Object>> wifiMapList = new ArrayList<Map<String, Object>>();
        for (ScanResult scanResult : scanResultList) {
            // WIFI信息
            Map<String, Object> wifiMap = new HashMap<String, Object>();
            wifiMapList.add(wifiMap);
            wifiMap.put("mac_address", scanResult.BSSID);
            wifiMap.put("mac_name", scanResult.SSID);
            // 信号强度
            wifiMap.put("signal_strength", scanResult.level);
        }
        if (wifiMapList.size() > 0)
            requestMap.put("wifi_towers", wifiMapList);
    }
    HttpConfig config = getHttpConfig();
    Params params = new Params();
    params.addParameter("json", JSON.toJSONString(requestMap));
    return doPost(config, getSetting("locationMobileGetLocation"), null, params, null, SinaLocationMap.class);
}
Also used : WifiManager(android.net.wifi.WifiManager) ScanResult(android.net.wifi.ScanResult) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Params(org.aisen.android.network.http.Params) NeighboringCellInfo(android.telephony.NeighboringCellInfo) TelephonyManager(android.telephony.TelephonyManager) JSONObject(com.alibaba.fastjson.JSONObject) HttpConfig(org.aisen.android.network.http.HttpConfig) GsmCellLocation(android.telephony.gsm.GsmCellLocation) Map(java.util.Map) SinaLocationMap(org.aisen.weibo.sina.sinasdk.bean.SinaLocationMap) HashMap(java.util.HashMap)

Aggregations

ScanResult (android.net.wifi.ScanResult)1 WifiManager (android.net.wifi.WifiManager)1 NeighboringCellInfo (android.telephony.NeighboringCellInfo)1 TelephonyManager (android.telephony.TelephonyManager)1 GsmCellLocation (android.telephony.gsm.GsmCellLocation)1 JSONObject (com.alibaba.fastjson.JSONObject)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 HttpConfig (org.aisen.android.network.http.HttpConfig)1 Params (org.aisen.android.network.http.Params)1 SinaLocationMap (org.aisen.weibo.sina.sinasdk.bean.SinaLocationMap)1