pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

    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="3nlrb3n" id='6reTW'><tfoot id='6reTW'></tfoot><dl id='6reTW'><fieldset id='6reTW'></fieldset></dl></div>
      1. 使用 json 獲取當前位置

        Get current location using json(使用 json 獲取當前位置)
        <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="l7zdbhj" id='eg8qz'><tfoot id='eg8qz'></tfoot><dl id='eg8qz'><fieldset id='eg8qz'></fieldset></dl></div>

                1. 本文介紹了使用 json 獲取當前位置的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  您好,我正在編寫一個應用程序,它獲取當前的經(jīng)緯度并將其轉(zhuǎn)換為相應的地址.我可以獲取緯度和經(jīng)度,但如何使用 json 將其轉(zhuǎn)換為相應的地址.我是 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();
                  

                  請幫幫我

                  提前致謝

                  推薦答案

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

                  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.

                  請參考 Google 地理編碼 API

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

                  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";
                  

                  希望這個答案會對你有所幫助.

                  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)驗,只有設備生成的緯度和經(jīng)度才能工作.然后調(diào)用

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

                  String currentLocation = getCurrentLocationViaJSON(lat, lng);
                  

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

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

                  相關文檔推薦

                  Help calculating X and Y from Latitude and Longitude in iPhone(幫助從 iPhone 中的緯度和經(jīng)度計算 X 和 Y)
                  Get user#39;s current location using GPS(使用 GPS 獲取用戶的當前位置)
                  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 返回負速度)
                  How to detect Location Provider ? GPS or Network Provider(如何檢測位置提供者?GPS 或網(wǎng)絡提供商)
                    <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="7dltbjz" id='24NVy'><tfoot id='24NVy'></tfoot><dl id='24NVy'><fieldset id='24NVy'></fieldset></dl></div>
                          1. 主站蜘蛛池模板: 卫生型双针压力表-高温防腐差压表-安徽康泰电气有限公司 | 胶水,胶粘剂,AB胶,环氧胶,UV胶水,高温胶,快干胶,密封胶,结构胶,电子胶,厌氧胶,高温胶水,电子胶水-东莞聚力-聚厉胶粘 | 济南玻璃安装_济南玻璃门_济南感应门_济南玻璃隔断_济南玻璃门维修_济南镜片安装_济南肯德基门_济南高隔间-济南凯轩鹏宇玻璃有限公司 | 整车VOC采样环境舱-甲醛VOC预处理舱-多舱法VOC检测环境仓-上海科绿特科技仪器有限公司 | 骨龄仪_骨龄检测仪_儿童骨龄测试仪_品牌生产厂家【品源医疗】 | 河北凯普威医疗器材有限公司,高档轮椅系列,推车系列,座厕椅系列,协步椅系列,拐扙系列,卫浴系列 | 冷水机-冰水机-冷冻机-冷风机-本森智能装备(深圳)有限公司 | 二手电脑回收_二手打印机回收_二手复印机回_硒鼓墨盒回收-广州益美二手电脑回收公司 | 不锈钢电动球阀_气动高压闸阀_旋塞疏水调节阀_全立阀门-来自温州工业阀门巨头企业 | 西安展台设计搭建_西安活动策划公司_西安会议会场布置_西安展厅设计西安旭阳展览展示 | 石家庄网站建设|石家庄网站制作|石家庄小程序开发|石家庄微信开发|网站建设公司|网站制作公司|微信小程序开发|手机APP开发|软件开发 | 北京翻译公司_同传翻译_字幕翻译_合同翻译_英语陪同翻译_影视翻译_翻译盖章-译铭信息 | 瓶盖扭矩测试仪-瓶盖扭力仪-全自动扭矩仪-济南三泉中石单品站 | 挤奶设备过滤纸,牛奶过滤纸,挤奶机过滤袋-济南蓝贝尔工贸有限公司 | 六自由度平台_六自由度运动平台_三自由度摇摆台—南京全控科技 | 高温高压釜(氢化反应釜)百科| 济南玻璃安装_济南玻璃门_济南感应门_济南玻璃隔断_济南玻璃门维修_济南镜片安装_济南肯德基门_济南高隔间-济南凯轩鹏宇玻璃有限公司 | 青岛侦探_青岛侦探事务所_青岛劝退小三_青岛婚外情取证-青岛王军侦探事务所 | 阻垢剂-反渗透缓蚀阻垢剂厂家-山东鲁东环保科技有限公司 | 铝机箱_铝外壳加工_铝外壳厂家_CNC散热器加工-惠州市铂源五金制品有限公司 | 企业微信营销_企业微信服务商_私域流量运营_艾客SCRM官网 | 大流量卧式砂磨机_强力分散机_双行星双动力混合机_同心双轴搅拌机-莱州市龙跃化工机械有限公司 | 办公室装修_上海办公室设计装修_时尚办公新主张-后街印象 | 强效碱性清洗剂-实验室中性清洗剂-食品级高纯氮气发生器-上海润榕科学器材有限公司 | 手持气象站_便携式气象站_农业气象站_负氧离子监测站-山东万象环境 | NBA直播_NBA直播免费观看直播在线_NBA直播免费高清无插件在线观看-24直播网 | 贵州科比特-防雷公司厂家提供贵州防雷工程,防雷检测,防雷接地,防雷设备价格,防雷产品报价服务-贵州防雷检测公司 | 泰来华顿液氮罐,美国MVE液氮罐,自增压液氮罐,定制液氮生物容器,进口杜瓦瓶-上海京灿精密机械有限公司 | 暖气片十大品牌厂家_铜铝复合暖气片厂家_暖气片什么牌子好_欣鑫达散热器 | 代办建筑资质升级-建筑资质延期就找上海国信启航 | 礼仪庆典公司,礼仪策划公司,庆典公司,演出公司,演艺公司,年会酒会,生日寿宴,动工仪式,开工仪式,奠基典礼,商务会议,竣工落成,乔迁揭牌,签约启动-东莞市开门红文化传媒有限公司 | 12cr1mov无缝钢管切割-15crmog无缝钢管切割-40cr无缝钢管切割-42crmo无缝钢管切割-Q345B无缝钢管切割-45#无缝钢管切割 - 聊城宽达钢管有限公司 | 新密高铝耐火砖,轻质保温砖价格,浇注料厂家直销-郑州荣盛窑炉耐火材料有限公司 | 沈阳缠绕膜价格_沈阳拉伸膜厂家_沈阳缠绕膜厂家直销 | 手板-手板模型-手板厂-手板加工-生产厂家,[东莞创域模型] | J.S.Bach 圣巴赫_高端背景音乐系统_官网 | 海峰资讯 - 专注装饰公司营销型网站建设和网络营销培训 | 复合肥,化肥厂,复合肥批发,化肥代理,复合肥品牌-红四方 | SRRC认证_电磁兼容_EMC测试整改_FCC认证_SDOC认证-深圳市环测威检测技术有限公司 | 河南卓美创业科技有限公司-河南卓美防雷公司-防雷接地-防雷工程-重庆避雷针-避雷器-防雷检测-避雷带-避雷针-避雷塔、机房防雷、古建筑防雷等-山西防雷公司 | 氧化锆陶瓷_氧化锆陶瓷加工_氧化锆陶瓷生产厂家-康柏工业陶瓷有限公司 |