久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    1. <tfoot id='6reTW'></tfoot>

        <bdo id='6reTW'></bdo><ul id='6reTW'></ul>
      <legend id='6reTW'><style id='6reTW'><dir id='6reTW'><q id='6reTW'></q></dir></style></legend>

        <small id='6reTW'></small><noframes id='6reTW'>

        <i id='6reTW'><tr id='6reTW'><dt id='6reTW'><q id='6reTW'><span id='6reTW'><b id='6reTW'><form id='6reTW'><ins id='6reTW'></ins><ul id='6reTW'></ul><sub id='6reTW'></sub></form><legend id='6reTW'></legend><bdo id='6reTW'><pre id='6reTW'><center id='6reTW'></center></pre></bdo></b><th id='6reTW'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='6reTW'><tfoot id='6reTW'></tfoot><dl id='6reTW'><fieldset id='6reTW'></fieldset></dl></div>
      1. 使用 json 獲取當(dāng)前位置

        Get current location using json(使用 json 獲取當(dāng)前位置)
        <tfoot id='eg8qz'></tfoot>

        <small id='eg8qz'></small><noframes id='eg8qz'>

          <tbody id='eg8qz'></tbody>
          • <bdo id='eg8qz'></bdo><ul id='eg8qz'></ul>
            <legend id='eg8qz'><style id='eg8qz'><dir id='eg8qz'><q id='eg8qz'></q></dir></style></legend>
            • <i id='eg8qz'><tr id='eg8qz'><dt id='eg8qz'><q id='eg8qz'><span id='eg8qz'><b id='eg8qz'><form id='eg8qz'><ins id='eg8qz'></ins><ul id='eg8qz'></ul><sub id='eg8qz'></sub></form><legend id='eg8qz'></legend><bdo id='eg8qz'><pre id='eg8qz'><center id='eg8qz'></center></pre></bdo></b><th id='eg8qz'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='eg8qz'><tfoot id='eg8qz'></tfoot><dl id='eg8qz'><fieldset id='eg8qz'></fieldset></dl></div>

                1. 本文介紹了使用 json 獲取當(dāng)前位置的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問題描述

                  您好,我正在編寫一個(gè)應(yīng)用程序,它獲取當(dāng)前的經(jīng)緯度并將其轉(zhuǎn)換為相應(yīng)的地址.我可以獲取緯度和經(jīng)度,但如何使用 json 將其轉(zhuǎn)換為相應(yīng)的地址.我是 json 新手.我嘗試了一些示例代碼,但沒有得到地址

                  Hi i a m writing an application whih gets the current latitude and longitude and convert it to corrsponding address.i can get the lattitude and longitutde but how to convert it to the corresponding address using json. i am new to json. i tried some sample codes butnot getting the address

                  這是我的代碼

                  import java.io.IOException;
                  import java.util.List;
                  import java.util.Locale;
                  
                  import android.content.Context;
                  import android.location.Address;
                  import android.location.Geocoder;
                  import android.location.Location;
                  import android.location.LocationListener;
                  import android.location.LocationManager;
                  import android.os.Bundle;
                  import android.support.v4.app.FragmentActivity;
                  import android.util.Log;
                  import android.view.Menu;
                  import android.widget.Toast;
                  
                  import com.google.android.gms.maps.CameraUpdate;
                  import com.google.android.gms.maps.CameraUpdateFactory;
                  import com.google.android.gms.maps.GoogleMap;
                  import com.google.android.gms.maps.SupportMapFragment;
                  import com.google.android.gms.maps.model.BitmapDescriptorFactory;
                  import com.google.android.gms.maps.model.CameraPosition;
                  import com.google.android.gms.maps.model.LatLng;
                  import com.google.android.gms.maps.model.LatLngBounds;
                  import com.google.android.gms.maps.model.Marker;
                  import com.google.android.gms.maps.model.MarkerOptions;
                  import com.google.android.maps.GeoPoint;
                  
                  
                  
                  public class GMapActivity extends FragmentActivity {
                  private GoogleMap map;
                  
                  
                         @Override
                  
                         protected void onCreate(Bundle savedInstanceState) {
                                super.onCreate(savedInstanceState);
                                setContentView(R.layout.activity_map);
                                LocationManager locManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
                  
                                LocationListener locListener = new GpsActivity(getBaseContext());
                          locManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, locListener);
                  
                  
                                if (map == null) {
                                       map = ((SupportMapFragment)  getSupportFragmentManager().findFragmentById(R.id.map))
                                               .getMap();
                  
                                  map.setMyLocationEnabled(true);
                  
                  
                                }
                         }
                  
                         @Override
                         public boolean onCreateOptionsMenu(Menu menu) {
                                // Inflate the menu; this adds items to the action bar if it is present.
                                getMenuInflater().inflate(R.menu.map, menu);
                                return true;
                         }
                  
                  
                  
                                private class GpsActivity implements LocationListener{
                                       Marker marker;
                                       Context mcontext;
                                       public GpsActivity(Context context){
                                             super();
                                             mcontext=context;
                                       }
                                       @Override
                                       public void onLocationChanged(Location location) {
                                             // TODO Auto-generated method stub
                                             if (location != null) {
                  
                                                    double latitude=location.getLatitude();
                  
                                                    double longitude=location.getLongitude();
                  
                                                    LatLng gpslocation=new LatLng(latitude,longitude);
                  
                  
                                                       Toast.makeText(getApplicationContext(),"" +gpslocation,
                                                                        Toast.LENGTH_LONG).show();
                  

                  請(qǐng)幫幫我

                  提前致謝

                  推薦答案

                  要改回人類可讀的格式,您也可以使用 Geocoder 但有時(shí)由于 google play 服務(wù)問題而無(wú)法正常工作.我將此 json 地理編碼用作以防萬(wàn)一.

                  To change back human readable format, you can also use Geocoder but that is not working sometimes because google play service problem. I used this json geocodeing as second option for in case.

                  請(qǐng)參考 Google 地理編碼 API

                  工作流程是通過您的緯度和經(jīng)度并獲取當(dāng)前位置.請(qǐng)求網(wǎng)址會(huì)是這樣的.

                  Workflow is pass your latitude and longitude and get current location. Request url gonna be like this.

                  String reqURL = "http://maps.googleapis.com/maps/api/geocode/json?latlng="+ lat+","+lng +"&sensor=true";
                  

                  希望這個(gè)答案會(huì)對(duì)你有所幫助.

                  Hopefully, this answer will help you.

                  public static JSONObject getLocationInfo(double lat, double lng) {
                  
                      HttpGet httpGet = new HttpGet("http://maps.googleapis.com/maps/api/geocode/json?latlng="+ lat+","+lng +"&sensor=true");
                      HttpClient client = new DefaultHttpClient();
                      HttpResponse response;
                      StringBuilder stringBuilder = new StringBuilder();
                  
                      try {
                          response = client.execute(httpGet);
                          HttpEntity entity = response.getEntity();
                          InputStream stream = entity.getContent();
                          int b;
                          while ((b = stream.read()) != -1) {
                              stringBuilder.append((char) b);
                          }
                      } catch (ClientProtocolException e) {
                      } catch (IOException e) {
                      }
                  
                      JSONObject jsonObject = new JSONObject();
                      try {
                          jsonObject = new JSONObject(stringBuilder.toString());
                      } catch (JSONException e) {
                          e.printStackTrace();
                      }
                  
                      return jsonObject;
                  }
                  
                  public static String getCurrentLocationViaJSON(double lat, double lng) {
                  
                      JSONObject jsonObj = getLocationInfo(lat, lng);
                      Log.i("JSON string =>", jsonObj.toString());
                  
                      String currentLocation = "testing";
                      String street_address = null;
                      String postal_code = null; 
                  
                      try {
                          String status = jsonObj.getString("status").toString();
                          Log.i("status", status);
                  
                          if(status.equalsIgnoreCase("OK")){
                              JSONArray results = jsonObj.getJSONArray("results");
                              int i = 0;
                              Log.i("i", i+ "," + results.length() ); //TODO delete this
                              do{
                  
                                  JSONObject r = results.getJSONObject(i);
                                  JSONArray typesArray = r.getJSONArray("types");
                                  String types = typesArray.getString(0);
                  
                                  if(types.equalsIgnoreCase("street_address")){
                                      street_address = r.getString("formatted_address").split(",")[0];
                                      Log.i("street_address", street_address);
                                  }else if(types.equalsIgnoreCase("postal_code")){
                                      postal_code = r.getString("formatted_address");
                                      Log.i("postal_code", postal_code);
                                  }
                  
                                  if(street_address!=null && postal_code!=null){
                                      currentLocation = street_address + "," + postal_code;
                                      Log.i("Current Location =>", currentLocation); //Delete this
                                      i = results.length();
                                  }
                  
                                  i++;
                              }while(i<results.length());
                  
                              Log.i("JSON Geo Locatoin =>", currentLocation);
                              return currentLocation;
                          }
                  
                      } catch (JSONException e) {
                          Log.e("testing","Failed to load JSON");
                          e.printStackTrace();
                      }
                      return null;
                  }
                  

                  根據(jù)我的經(jīng)驗(yàn),只有設(shè)備生成的緯度和經(jīng)度才能工作.然后調(diào)用

                  As my experience, only device generated latitude and longitude will work. Then call

                  String currentLocation = getCurrentLocationViaJSON(lat, lng);
                  

                  這篇關(guān)于使用 json 獲取當(dāng)前位置的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  Help calculating X and Y from Latitude and Longitude in iPhone(幫助從 iPhone 中的緯度和經(jīng)度計(jì)算 X 和 Y)
                  Get user#39;s current location using GPS(使用 GPS 獲取用戶的當(dāng)前位置)
                  IllegalArgumentException thrown by requestLocationUpdate()(requestLocationUpdate() 拋出的 IllegalArgumentException)
                  How reliable is LocationManager#39;s getLastKnownLocation and how often is it updated?(LocationManager 的 getLastKnownLocation 有多可靠,多久更新一次?)
                  CLLocation returning negative speed(CLLocation 返回負(fù)速度)
                  How to detect Location Provider ? GPS or Network Provider(如何檢測(cè)位置提供者?GPS 或網(wǎng)絡(luò)提供商)
                    <tbody id='24NVy'></tbody>

                      <bdo id='24NVy'></bdo><ul id='24NVy'></ul>

                        • <tfoot id='24NVy'></tfoot>

                          <legend id='24NVy'><style id='24NVy'><dir id='24NVy'><q id='24NVy'></q></dir></style></legend>

                            <small id='24NVy'></small><noframes id='24NVy'>

                            <i id='24NVy'><tr id='24NVy'><dt id='24NVy'><q id='24NVy'><span id='24NVy'><b id='24NVy'><form id='24NVy'><ins id='24NVy'></ins><ul id='24NVy'></ul><sub id='24NVy'></sub></form><legend id='24NVy'></legend><bdo id='24NVy'><pre id='24NVy'><center id='24NVy'></center></pre></bdo></b><th id='24NVy'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='24NVy'><tfoot id='24NVy'></tfoot><dl id='24NVy'><fieldset id='24NVy'></fieldset></dl></div>
                          1. 主站蜘蛛池模板: 免费看av大片 | 色婷婷av777 av免费网站在线 | 一区二区精品在线 | 欧美手机在线 | 国产精品久久久久久中文字 | 97视频在线观看免费 | 欧美精品中文字幕久久二区 | 欧美在线一区二区三区四区 | 日韩二| 国产 日韩 欧美 中文 在线播放 | 国产视频一区二区三区四区五区 | 色免费在线视频 | 日韩免费一区二区 | 国产精品久久久久国产a级 欧美日本韩国一区二区 | 亚洲一区二区三区在线视频 | 国产成人亚洲精品 | 日韩电影一区二区三区 | 欧美一级www片免费观看 | 成人免费视频网站在线看 | 成人毛片视频免费 | 日韩在线播放网址 | 这里只有精品999 | 久久精品国产精品青草 | 99精品电影| 国产精品一区二区三区久久 | 国产精品成人久久久久a级 久久蜜桃av一区二区天堂 | 国产成人精品视频在线观看 | 欧美精品成人 | 欧美精品第一区 | 超碰精品在线观看 | 极品国产视频 | 国产精品视屏 | 99色综合 | 全免费a级毛片免费看视频免费下 | 日韩中文一区 | 欧美福利 | 欧美综合一区二区三区 | 精品无码久久久久久国产 | 中文字幕一区在线 | 免费在线观看一区二区 | 黄色网页在线 |