{"id":1021,"date":"2017-10-17T10:55:01","date_gmt":"2017-10-17T02:55:01","guid":{"rendered":"http:\/\/www.siediyer.cn\/?p=1021"},"modified":"2017-10-17T10:55:03","modified_gmt":"2017-10-17T02:55:03","slug":"android%e5%bc%80%e5%8f%91%e8%8e%b7%e5%8f%96gps%e4%bd%8d%e7%bd%ae%ef%bc%8c%e5%8c%85%e5%90%abapnwifigps-%e5%87%a0%e7%a7%8d%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.siediyer.cn\/?p=1021","title":{"rendered":"Android\u5f00\u53d1\u83b7\u53d6GPS\u4f4d\u7f6e\uff0c\u5305\u542bapn\\wifi\\gps \u51e0\u79cd\u65b9\u6cd5"},"content":{"rendered":"<p>\u4e00\u90e8\u5206\uff1a\u51e0\u79cd\u5b9a\u4f4d\u7b80\u8ff0<\/p>\n<div>\n<div>1.gps\u5b9a\u4f4d\uff1a<\/div>\n<div><\/div>\n<div>\u4f18\u70b9\uff1a\u6700\u7b80\u5355\u7684\u624b\u673a\u5b9a\u4f4d\u65b9\u5f0f\u5f53\u7136\u662f\u901a\u8fc7GPS\u6a21\u5757\uff08\u73b0\u5728\u5927\u90e8\u5206\u7684\u667a\u80fd\u673a\u5e94\u8be5\u90fd\u6709\u4e86\uff09\u3002GPS\u65b9\u5f0f\u51c6\u786e\u5ea6\u662f\u6700\u9ad8\u7684<\/div>\n<div>\u7f3a\u70b91.\u6bd4\u8f83\u8017\u7535\uff1b<\/div>\n<div>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 2.\u7edd\u5927\u90e8\u5206\u7528\u6237\u9ed8\u8ba4\u4e0d\u5f00\u542fGPS\u6a21\u5757\uff1b<\/div>\n<div>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 3.\u4eceGPS\u6a21\u5757\u542f\u52a8\u5230\u83b7\u53d6\u7b2c\u4e00\u6b21\u5b9a\u4f4d\u6570\u636e\uff0c\u53ef\u80fd\u9700\u8981\u6bd4\u8f83\u957f\u7684\u65f6\u95f4\uff1b<\/div>\n<div>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 4.\u5ba4\u5185\u51e0\u4e4e\u65e0\u6cd5\u4f7f\u7528\u3002<\/div>\n<div>\u8fd9\u5176\u4e2d\uff0c\u7f3a\u70b92,3\u90fd\u662f\u6bd4\u8f83\u81f4\u547d\u7684\u3002\u9700\u8981\u6307\u51fa\u7684\u662f\uff0cGPS\u8d70\u7684\u662f\u536b\u661f\u901a\u4fe1\u7684\u901a\u9053\uff0c\u5728\u6ca1\u6709\u7f51\u7edc\u8fde\u63a5\u7684\u60c5\u51b5\u4e0b\u4e5f\u80fd\u7528\u3002<\/div>\n<div><\/div>\n<div>\u6709\u7f51\u7edc\u3001\u5ba4\u5185\u4e0d\u53ef\u7528\u3001\u5b9a\u4f4d\u65f6\u95f4\u957f\u3001\u4f4d\u7f6e\u7cbe\u786e<\/div>\n<div><\/div>\n<div>2.\u57fa\u7ad9\u5b9a\u4f4d<\/div>\n<div>\u5927\u81f4\u601d\u8def\u5c31\u662f\u91c7\u96c6\u5230\u624b\u673a\u4e0a\u7684\u57fa\u7ad9ID\u53f7\uff08cellid\uff09\u548c\u5176\u5b83\u7684\u4e00\u4e9b\u4fe1\u606f\uff08MNC\uff0cMCC\uff0cLAC\u7b49\u7b49\uff09\uff0c\u7136\u540e\u901a\u8fc7\u7f51\u7edc\u8bbf\u95ee\u4e00\u4e9b\u5b9a\u4f4d\u670d\u52a1\uff0c\u83b7\u53d6 \u5e76\u8fd4\u56de\u5bf9\u5e94\u7684\u7ecf\u7eac\u5ea6\u5750\u6807\u3002\u57fa\u7ad9\u5b9a\u4f4d\u7684\u7cbe\u786e\u5ea6\u4e0d\u5982GPS\uff0c\u597d\u5904\u662f\u80fd\u591f\u5728\u5ba4\u5185\u7528\uff0c\u53ea\u8981\u7f51\u7edc\u901a\u7545\u5c31\u884c\u3002<\/div>\n<div><\/div>\n<div>\u6709\u7f51\u7edc \u5ba4\u5185\u53ef\u7528 \u5b9a\u4f4d\u65b9\u5f0f\u4e0d\u7cbe\u786e<\/div>\n<div><\/div>\n<div>3.WIFI\u5b9a\u4f4d<\/div>\n<div>\u548c\u57fa\u7ad9\u5b9a\u4f4d\u7c7b\u4f3c\uff0c\u8fd9\u79cd\u65b9\u5f0f\u662f\u901a\u8fc7\u83b7\u53d6\u5f53\u524d\u6240\u7528\u7684wifi\u7684\u4e00\u4e9b\u4fe1\u606f\uff0c\u7136\u540e\u8bbf\u95ee\u7f51\u7edc\u4e0a\u7684\u5b9a\u4f4d\u670d\u52a1\u4ee5\u83b7\u5f97\u7ecf\u7eac\u5ea6\u5750\u6807\u3002\u56e0\u4e3a\u5b83\u548c\u57fa\u7ad9\u5b9a\u4f4d\u5176\u5b9e\u90fd\u9700\u8981\u4f7f \u7528\u7f51\u7edc\uff0c\u6240\u4ee5\u5728Android\u4e5f\u7edf\u79f0\u4e3aNetwork\u65b9\u5f0f\u3002<\/div>\n<div><\/div>\n<div>\u4e0e\u57fa\u7ad9\u5b9a\u4f4d\u7c7b\u4f3c<\/div>\n<div><\/div>\n<div>4.AGPS\u5b9a\u4f4d<br \/>\n\u6700\u540e\u9700\u8981\u89e3\u91ca\u4e00\u70b9\u7684\u662fAGPS\u65b9\u5f0f\u3002\u5f88\u591a\u4eba\u5c06\u5b83\u548c\u57fa\u7ad9\u5b9a\u4f4d\u6df7\u4e3a\u4e00\u8c08\uff0c\u4f46\u5176\u5b9eAGPS\u7684\u672c\u8d28\u4ecd\u7136\u662fGPS\uff0c\u53ea\u662f\u5b83\u4f1a\u4f7f\u7528\u57fa\u7ad9\u4fe1\u606f\u5bf9\u83b7\u53d6GPS\u8fdb\u884c\u8f85\u52a9\uff0c\u7136\u540e \u8fd8\u80fd\u5bf9\u83b7\u53d6\u5230\u7684GPS\u7ed3\u679c\u8fdb\u884c\u4fee\u6b63\uff0c\u6240\u4ee5AGPS\u8981\u6bd4\u4f20\u7edf\u7684GPS\u66f4\u5feb\uff0c\u51c6\u786e\u5ea6\u7565\u9ad8\u3002<\/div>\n<div><\/div>\n<div>\u6709\u7f51\u7edc\u3001\u7c7b\u4f3cgps\u5b9a\u4f4d\u3001\u4f46\u6bd4\u4f20\u7edfGps\u5b9a\u4f4d\u66f4\u5feb\uff0c\u51c6\u786e\u5ea6\u7565\u9ad8<\/div>\n<div><\/div>\n<div>\u7b2c\u4e8c\u90e8\u5206\uff1a<\/div>\n<div>locationManager.getLastKnownLocation()\u603b\u662f\u4f1a\u51fa\u73b0\u53d6\u4e0d\u5230\u6570\u636e\u7684\u60c5\u51b5\uff0c\u6240\u4ee5\u8fd9\u91cc\u6ca1\u6709\u4f7f\u7528\u8fd9\u4e2a\u65b9\u6cd5\uff0c\u907f\u514d \u4e86\u53d6\u4e0d\u5230\u6570\u636e\u7684\u95ee\u9898<\/div>\n<div><\/div>\n<div>\u7b2c\u4e09\u90e8\u5206\uff1a\u4f7f\u7528\u5f02\u6b65\u52a0\u8f7d\uff0c\u63d0\u9ad8\u6027\u80fd<\/div>\n<div><\/div>\n<div>================================\u4ee3\u7801===========================<\/div>\n<div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1022\" src=\"http:\/\/www.siediyer.cn\/wp-content\/uploads\/2017\/10\/20140113010033110.png\" width=\"480\" height=\"854\" alt=\"\\\" srcset=\"https:\/\/qiniu.shijitianchen.com\/2017\/10\/20140113010033110.png 480w, https:\/\/qiniu.shijitianchen.com\/2017\/10\/20140113010033110-169x300.png 169w\" sizes=\"auto, (max-width: 480px) 100vw, 480px\" \/>\u00a0\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1023\" src=\"http:\/\/www.siediyer.cn\/wp-content\/uploads\/2017\/10\/20140113010110961.png\" width=\"480\" height=\"854\" alt=\"\\\" srcset=\"https:\/\/qiniu.shijitianchen.com\/2017\/10\/20140113010110961.png 480w, https:\/\/qiniu.shijitianchen.com\/2017\/10\/20140113010110961-169x300.png 169w\" sizes=\"auto, (max-width: 480px) 100vw, 480px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>1.Activity<\/p>\n<pre class=\"lang:default decode:true \">package com.example.gpsdemo;  \r\n \r\nimport com.example.gpsdemo.util.GetLocation;  \r\nimport com.example.gpsdemo.util.LMLocation;  \r\n \r\nimport android.app.Activity;  \r\nimport android.app.AlertDialog;  \r\nimport android.app.ProgressDialog;  \r\nimport android.os.Bundle;  \r\nimport android.view.View;  \r\nimport android.view.View.OnClickListener;  \r\nimport android.widget.Button;  \r\nimport android.widget.TextView;  \r\n \r\npublic class MainActivity extends Activity {  \r\n    LMLocation lmLocation;  \r\n    TextView textView;  \r\n    public MainActivity instance;  \r\n    private AlertDialog dialog;  \r\n    @Override\r\n    public void onCreate(Bundle savedInstanceState) {  \r\n        super.onCreate(savedInstanceState);  \r\n        setContentView(R.layout.activity_main);  \r\n        textView = (TextView) findViewById(R.id.textView2);  \r\n        instance = this;  \r\n        dialog = new ProgressDialog(MainActivity.this);  \r\n        dialog.setTitle(\"\u8bf7\u7a0d\u7b49...\");  \r\n        dialog.setMessage(\"\u6b63\u5728\u5b9a\u4f4d...\");  \r\n        Button button = (Button) findViewById(R.id.button1);  \r\n        button.setOnClickListener(new OnClickListener() {  \r\n \r\n            @Override\r\n            public void onClick(View v) {  \r\n                \/\/ TODO Auto-generated method stub\r\n                new GetLocation(dialog, textView, instance).DisplayLocation();  \r\n            }  \r\n        });  \r\n \r\n    }  \r\n \r\n}  \r\n<\/pre>\n<p>2.\u4e0eMainActivity\u5bf9\u5e94\u7684\u5e03\u5c40<\/p>\n<pre class=\"lang:default decode:true \">&lt;xmlns:tools=\"http:\/\/schemas.android.com\/tools\"\r\n    android:layout_width=\"match_parent\"\r\n    android:layout_height=\"match_parent\" &gt;\r\n \r\n     \r\n       &lt;android:id=\"@+id\/textView2\"\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:layout_centerHorizontal=\"true\"\r\n        android:layout_centerVertical=\"true\"\r\n        android:padding=\"@dimen\/padding_medium\"\r\n        android:text=\"@string\/hello_world\"\r\n        tools:context=\".MainActivity\" \/&gt;\r\n \r\n     \r\n        &lt;android:id=\"@+id\/button1\"\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:layout_alignParentTop=\"true\"\r\n        android:layout_alignRight=\"@+id\/textView2\"\r\n        android:layout_marginRight=\"52dp\"\r\n        android:text=\"\u5b9a\u4f4d\" \/&gt;\r\n<\/pre>\n<p>3.AndroidManifest.xml<\/p>\n<pre class=\"lang:default decode:true \">package=\"com.example.gpsdemo\"\r\n    android:versionCode=\"1\"\r\n    android:versionName=\"1.0\" &gt;\r\n \r\n    &lt;uses-sdk&lt; li=\"\"&gt;\r\n        android:minSdkVersion=\"8\"\r\n        android:targetSdkVersion=\"15\" \/&gt;\r\n \r\n    &lt;application&lt; li=\"\"&gt;\r\n        android:icon=\"@drawable\/ic_launcher\"\r\n        android:label=\"@string\/app_name\"\r\n        android:theme=\"@style\/AppTheme\" &gt;\r\n        &lt;activity&lt; li=\"\"&gt;\r\n            android:name=\".MainActivity\"\r\n            android:label=\"@string\/title_activity_main\" &gt;<\/pre>\n<p>4.\u5de5\u5177\u7c7b\u4e24\u4e2a\uff1a\uff081\uff09<\/p>\n<pre class=\"lang:default decode:true \">package com.example.gpsdemo.util;  \r\n \r\nimport android.app.AlertDialog;  \r\nimport android.content.Context;  \r\nimport android.os.AsyncTask;  \r\nimport android.util.Log;  \r\nimport android.widget.TextView;  \r\n \r\npublic class GetLocation {  \r\n    AlertDialog dialog;  \r\n    TextView textView;  \r\n    Context context;  \r\n \r\n    public GetLocation(AlertDialog dialog, TextView textView, Context context) {  \r\n        this.dialog = dialog;  \r\n        this.textView = textView;  \r\n        this.context = context;  \r\n \r\n    }  \r\n \r\n    public void DisplayLocation() {  \r\n        new AsyncTask() {  \r\n \r\n            @Override\r\n            protected String doInBackground=\\'#\\'\"  \r\n                LMLocation location = null;  \r\n                try {  \r\n                    location = new GPSLocation().getGPSInfo(context);  \r\n                } catch (Exception e) {  \r\n                    \/\/ TODO Auto-generated catch block\r\n                    e.printStackTrace();  \r\n                }  \r\n                if (location == null)  \r\n                    return null;  \r\n                Log.d(\"debug\", location.toString());  \r\n                return location.toString();  \r\n \r\n            }  \r\n \r\n            @Override\r\n            protected void onPreExecute() {  \r\n                dialog.show();  \r\n                super.onPreExecute();  \r\n            }  \r\n \r\n            @Override\r\n            protected void onPostExecute(String result) {  \r\n                if (result == null) {  \r\n                    textView.setText(\"\u5b9a\u4f4d\u5931\u8d25\u4e86...\");  \r\n                } else {  \r\n                    textView.setText(result);  \r\n                }  \r\n                dialog.dismiss();  \r\n                super.onPostExecute(result);  \r\n            }  \r\n \r\n        }.execute();  \r\n    }  \r\n \r\n}  \r\n<\/pre>\n<p>2.<\/p>\n<pre class=\"lang:default decode:true \">package com.example.gpsdemo.util;  \r\n \r\nimport java.io.BufferedReader;  \r\nimport java.io.InputStreamReader;  \r\n \r\nimport org.apache.http.HttpEntity;  \r\nimport org.apache.http.HttpHost;  \r\nimport org.apache.http.HttpResponse;  \r\nimport org.apache.http.client.HttpClient;  \r\nimport org.apache.http.client.methods.HttpPost;  \r\nimport org.apache.http.conn.params.ConnRouteParams;  \r\nimport org.apache.http.entity.StringEntity;  \r\nimport org.apache.http.impl.client.DefaultHttpClient;  \r\nimport org.apache.http.params.HttpConnectionParams;  \r\nimport org.json.JSONArray;  \r\nimport org.json.JSONObject;  \r\n \r\nimport android.content.Context;  \r\nimport android.database.Cursor;  \r\nimport android.net.ConnectivityManager;  \r\nimport android.net.NetworkInfo.State;  \r\nimport android.net.Uri;  \r\nimport android.net.wifi.WifiManager;  \r\nimport android.telephony.TelephonyManager;  \r\nimport android.telephony.gsm.GsmCellLocation;  \r\nimport android.util.Log;  \r\n \r\n\/**\r\n * ******************************************\r\n * \u63cf\u8ff0::GPS\u4fe1\u606f\u83b7\u53d6\r\n * @version 2.0\r\n ******************************************** \r\n *\/\r\npublic class GPSLocation {  \r\n    private static int postType = -1;  \r\n    public static final int DO_3G = 0;  \r\n    public static final int DO_WIFI = 1;  \r\n    public static final int NO_CONNECTION = 2;  \r\n \r\n    \/**\r\n     * \u7f51\u7edc\u65b9\u5f0f\u68c0\u67e5\r\n     *\/\r\n    private static int netCheck(Context context) {  \r\n        ConnectivityManager conMan = (ConnectivityManager) context  \r\n                .getSystemService(Context.CONNECTIVITY_SERVICE);  \r\n        State mobile = conMan.getNetworkInfo(ConnectivityManager.TYPE_MOBILE)  \r\n                .getState();  \r\n        State wifi = conMan.getNetworkInfo(ConnectivityManager.TYPE_WIFI)  \r\n                .getState();  \r\n        if (wifi.equals(State.CONNECTED)) {  \r\n            return DO_WIFI;  \r\n        } else if (mobile.equals(State.CONNECTED)) {  \r\n            return DO_3G;  \r\n        } else {  \r\n            return NO_CONNECTION;  \r\n        }  \r\n    }  \r\n \r\n    \/**\r\n     * \u83b7\u53d6WifiManager\u83b7\u53d6\u4fe1\u606f\r\n     *\/\r\n    private static JSONObject getInfoByWifiManager(Context context)  \r\n            throws Exception {  \r\n        JSONObject holder = new JSONObject();  \r\n        holder.put(\"version\", \"1.1.0\");  \r\n        holder.put(\"host\", \"maps.google.com\");  \r\n        holder.put(\"address_language\", \"zh_CN\");  \r\n        holder.put(\"request_address\", true);  \r\n \r\n        WifiManager wifiManager = (WifiManager) context  \r\n                .getSystemService(Context.WIFI_SERVICE);  \r\n \r\n        if (wifiManager.getConnectionInfo().getBSSID() == null) {  \r\n            throw new RuntimeException(\"bssid is null\");  \r\n        }  \r\n \r\n        JSONArray array = new JSONArray();  \r\n        JSONObject data = new JSONObject();  \r\n        data.put(\"mac_address\", wifiManager.getConnectionInfo().getBSSID());  \r\n        data.put(\"signal_strength\", 8);  \r\n        data.put(\"age\", 0);  \r\n        array.put(data);  \r\n        holder.put(\"wifi_towers\", array);  \r\n        return holder;  \r\n    }  \r\n \r\n    \/**\r\n     * \u83b7\u53d6TelephoneManager\u83b7\u53d6\u4fe1\u606f\r\n     *\/\r\n    private static JSONObject getInfoByTelephoneManager(Context context)  \r\n            throws Exception {  \r\n        JSONObject holder = new JSONObject();  \r\n        holder.put(\"version\", \"1.1.0\");  \r\n        holder.put(\"host\", \"maps.google.com\");  \r\n        holder.put(\"address_language\", \"zh_CN\");  \r\n        holder.put(\"request_address\", true);  \r\n        TelephonyManager tm = (TelephonyManager) context  \r\n                .getSystemService(Context.TELEPHONY_SERVICE);  \r\n        GsmCellLocation gcl = (GsmCellLocation) tm.getCellLocation();  \r\n        int cid = gcl.getCid();  \r\n        int lac = gcl.getLac();  \r\n        int mcc = Integer.valueOf(tm.getNetworkOperator().substring(0, 3));  \r\n        int mnc = Integer.valueOf(tm.getNetworkOperator().substring(3, 5));  \r\n        JSONArray array = new JSONArray();  \r\n        JSONObject data = new JSONObject();  \r\n        data.put(\"cell_id\", cid);  \r\n        data.put(\"location_area_code\", lac);  \r\n        data.put(\"mobile_country_code\", mcc);  \r\n        data.put(\"mobile_network_code\", mnc);  \r\n        array.put(data);  \r\n        holder.put(\"cell_towers\", array);  \r\n        return holder;  \r\n    }  \r\n \r\n    \/**\r\n     * \u901a\u8fc7wifi\u83b7\u53d6GPS\u4fe1\u606f\r\n     *\/\r\n    private static HttpResponse connectionForGPS(Context context)  \r\n            throws Exception {  \r\n        HttpResponse httpResponse = null;  \r\n        postType = netCheck(context);  \r\n        if (postType == NO_CONNECTION) {  \r\n            return null;  \r\n        } else {  \r\n            if (postType == DO_WIFI) {  \r\n                if ((httpResponse = doOrdinary(context,  \r\n                        getInfoByWifiManager(context))) != null) {  \r\n                    return httpResponse;  \r\n                } else if ((httpResponse = doAPN(context,  \r\n                        getInfoByWifiManager(context))) != null) {  \r\n                    return httpResponse;  \r\n                } else if ((httpResponse = doOrdinary(context,  \r\n                        getInfoByTelephoneManager(context))) != null) {  \r\n                    return httpResponse;  \r\n                } else if ((httpResponse = doAPN(context,  \r\n                        getInfoByTelephoneManager(context))) != null) {  \r\n                    return httpResponse;  \r\n                }  \r\n            }  \r\n            if (postType == DO_3G) {  \r\n                if ((httpResponse = doOrdinary(context,  \r\n                        getInfoByTelephoneManager(context))) != null) {  \r\n                    return httpResponse;  \r\n                } else if ((httpResponse = doAPN(context,  \r\n                        getInfoByTelephoneManager(context))) != null) {  \r\n                    return httpResponse;  \r\n                }  \r\n            }  \r\n            return null;  \r\n        }  \r\n    }  \r\n \r\n    \/**\r\n     * \u901a\u8fc7\u666e\u901a\u65b9\u5f0f\u5b9a\u4f4d\r\n     *\/\r\n    private static HttpResponse doOrdinary(Context context, JSONObject holder) {  \r\n        HttpResponse response = null;  \r\n        try {  \r\n            HttpClient httpClient = new DefaultHttpClient();  \r\n            HttpConnectionParams.setConnectionTimeout(httpClient.getParams(),  \r\n                    20 * 1000);  \r\n            HttpConnectionParams  \r\n                    .setSoTimeout(httpClient.getParams(), 20 * 1000);  \r\n            HttpPost post = new HttpPost(\"http:\/\/74.125.71.147\/loc\/json\");  \r\n            StringEntity se = new StringEntity(holder.toString());  \r\n            post.setEntity(se);  \r\n            response = httpClient.execute(post);  \r\n        } catch (Exception e) {  \r\n            e.printStackTrace();  \r\n            return null;  \r\n        }  \r\n        return response;  \r\n    }  \r\n \r\n    \/**\r\n     * \u901a\u8fc7\u57fa\u7ad9\u5b9a\u4f4d\r\n     *\/\r\n    private static HttpResponse doAPN(Context context, JSONObject holder) {  \r\n        HttpResponse response = null;  \r\n        try {  \r\n            HttpClient httpClient = new DefaultHttpClient();  \r\n            HttpConnectionParams.setConnectionTimeout(httpClient.getParams(),  \r\n                    20 * 1000);  \r\n            HttpConnectionParams  \r\n                    .setSoTimeout(httpClient.getParams(), 20 * 1000);  \r\n            HttpPost post = new HttpPost(\"http:\/\/74.125.71.147\/loc\/json\");  \r\n            \/\/ \u8bbe\u7f6e\u4ee3\u7406\r\n            Uri uri = Uri.parse(\"content:\/\/telephony\/carriers\/preferapn\"); \/\/ \u83b7\u53d6\u5f53\u524d\u6b63\u5728\u4f7f\u7528\u7684APN\u63a5\u5165\u70b9  \r\n            Cursor mCursor = context.getContentResolver().query(uri, null,  \r\n                    null, null, null);  \r\n            if (mCursor != null) {  \r\n                if (mCursor.moveToFirst()) {  \r\n                    String proxyStr = mCursor.getString(mCursor  \r\n                            .getColumnIndex(\"proxy\"));  \r\n                    if (proxyStr != null &amp;&amp; proxyStr.trim().length() &gt; 0) {  \r\n                        HttpHost proxy = new HttpHost(proxyStr, 80);  \r\n                        httpClient.getParams().setParameter(  \r\n                                ConnRouteParams.DEFAULT_PROXY, proxy);  \r\n                    }  \r\n                }  \r\n            }  \r\n            StringEntity se = new StringEntity(holder.toString());  \r\n            post.setEntity(se);  \r\n            response = httpClient.execute(post);  \r\n        } catch (Exception e) {  \r\n            e.printStackTrace();  \r\n            return null;  \r\n        }  \r\n        return response;  \r\n    }  \r\n \r\n    \/**\r\n     * GPS\u4fe1\u606f\u89e3\u6790\r\n     *\/\r\n    public static LMLocation getGPSInfo(Context context) throws Exception {  \r\n        HttpResponse response = connectionForGPS(context);  \r\n        if (response == null) {  \r\n            Log.d(\"GPSLocation\", \"response == null\");  \r\n            return null;  \r\n        }  \r\n        LMLocation location = null;  \r\n        if (response.getStatusLine().getStatusCode() == 200) {  \r\n            location = new LMLocation();  \r\n            HttpEntity entity = response.getEntity();  \r\n            BufferedReader br;  \r\n            try {  \r\n                br = new BufferedReader(new InputStreamReader(  \r\n                        entity.getContent()));  \r\n                StringBuffer sb = new StringBuffer();  \r\n                String result = br.readLine();  \r\n                while (result != null) {  \r\n                    sb.append(result);  \r\n                    result = br.readLine();  \r\n                }  \r\n                JSONObject json = new JSONObject(sb.toString());  \r\n                JSONObject lca = json.getJSONObject(\"location\");  \r\n \r\n                location.setAccess_token(json.getString(\"access_token\"));  \r\n                if (lca != null) {  \r\n                    if (lca.has(\"accuracy\"))  \r\n                        location.setAccuracy(lca.getString(\"accuracy\"));  \r\n                    if (lca.has(\"longitude\"))  \r\n                        location.setLatitude(lca.getDouble(\"longitude\"));  \r\n                    if (lca.has(\"latitude\"))  \r\n                        location.setLongitude(lca.getDouble(\"latitude\"));  \r\n                    if (lca.has(\"address\")) {  \r\n                        JSONObject address = lca.getJSONObject(\"address\");  \r\n                        if (address != null) {  \r\n                            if (address.has(\"region\"))  \r\n                                location.setRegion(address.getString(\"region\"));  \r\n                            if (address.has(\"street_number\"))  \r\n                                location.setStreet_number(address  \r\n                                        .getString(\"street_number\"));  \r\n                            if (address.has(\"country_code\"))  \r\n                                location.setCountry_code(address  \r\n                                        .getString(\"country_code\"));  \r\n                            if (address.has(\"street\"))  \r\n                                location.setStreet(address.getString(\"street\"));  \r\n                            if (address.has(\"city\"))  \r\n                                location.setCity(address.getString(\"city\"));  \r\n                            if (address.has(\"country\"))  \r\n                                location.setCountry(address  \r\n                                        .getString(\"country\"));  \r\n                        }  \r\n                    }  \r\n                }  \r\n            } catch (Exception e) {  \r\n                e.printStackTrace();  \r\n                location = null;  \r\n            }  \r\n        }  \r\n        return location;  \r\n    }  \r\n \r\n}  \r\n\uff09<\/pre>\n<p>&nbsp;<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u90e8\u5206\uff1a\u51e0\u79cd\u5b9a\u4f4d\u7b80\u8ff0 1.gps\u5b9a\u4f4d\uff1a \u4f18\u70b9\uff1a\u6700\u7b80\u5355\u7684\u624b\u673a\u5b9a\u4f4d\u65b9\u5f0f\u5f53\u7136\u662f\u901a\u8fc7GPS\u6a21\u5757\uff08\u73b0\u5728\u5927\u90e8\u5206\u7684\u667a\u80fd\u673a\u5e94\u8be5 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1022,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[49],"tags":[69,71],"class_list":["post-1021","post","type-post","status-publish","format-standard","hentry","category-android","tag-gis","tag-71"],"_links":{"self":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts\/1021","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1021"}],"version-history":[{"count":1,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts\/1021\/revisions"}],"predecessor-version":[{"id":1024,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts\/1021\/revisions\/1024"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/media\/1022"}],"wp:attachment":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1021"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1021"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1021"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}