通过经纬度获取地理位置信息
2017-11-17 17:06
633 查看
最近做一个车载设备app,设备获取北斗gps数据上传的到后台,app通过后台提供的经纬度反取地理编码位置,支持Google和百度。
获取地理位置url
获取详细街道地址
获取地理位置url
//Google public String getGoogleUrl(boolean isCn, String longitude,String latitude) { if (!isCn) { return "http://maps.google.com/maps/api/geocode/json?latlng="+latitude+","+longitude+"&sensor=false&language=" + Locale.getDefault().getLanguage() + "-" + Locale.getDefault().getCountry(); } else { return "http://ditu.google.cn/maps/api/geocode/json?latlng="+latitude+","+longitude+"&sensor=false&language=" + Locale.getDefault().getLanguage() + "-" + Locale.getDefault().getCountry(); } } //百度,到百度地图获取ak密钥 public String getBaiduUrl(String longitude,String latitude) { return "http://api.map.baidu.com/geocoder/v2/?" + "ak=ahH7ICSO020gfifmGVog5OTimwq" + "&mcode=DC:B1:26:FF:66:49:62:85:98:16:AE:2A:E8:69:A9:EE:AC:14:3B;com.icar.taxi" + "&output=json" + "&pois=0& 4000 amp;location="+latitude+","+longitude; }
获取详细街道地址
/** * @return 详细街道地址 */ public String getAddress(String url){ //定义一个HttpClient,用于向指定地址发送请求 HttpClient client = new DefaultHttpClient(); //向指定地址发送Get请求 HttpGet hhtpGet = new HttpGet(url); StringBuilder sb = new StringBuilder(); try { //获取服务器响应 HttpResponse response = client.execute(hhtpGet); HttpEntity entity = response.getEntity(); if(entity !=null){ BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent(),"UTF-8"),8192); String line =null; while ((line= reader.readLine())!=null){ sb.append(line +"\n"); } reader.close(); } //将服务器返回的字符串转换为JSONObject 对象 JSONObject jsonObject = new JSONObject(sb.toString()); //从JSONObject 中取出location 属性 if (AppConfig.mapType()) { return jsonObject.optJSONObject("result").optString("formatted_address"); } else { return jsonObject.optJSONArray("results").optJSONObject(0).optString("formatted_address"); } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return null; }
相关文章推荐
- Android 通过经纬度获取地理位置信息
- 通过经纬度获取地理位置详细信息
- Android 通过经纬度获取地理位置信息
- 通过ip获取地理位置信息
- java调用百度地图API通过URL根据地理位置中文处理返回值获取经纬度
- 通过GeoIP2分析访问者IP获取地理位置信息
- IP定位:通过qqwry.bat IP库获取指定IP的地理位置信息
- android百度离线地图可以通过经纬度获取当前地理信息么(不联网的情况下)
- 通过GeoIP2分析访问者IP获取地理位置信息
- PHP根据地理位置信息获取经纬度
- Android通过百度地图API用Service和Alarm在后台定时获取地理位置信息
- Android 如何获取手机经纬度和地理位置信息
- Javascript通过腾讯,新浪,谷歌 IP接口获取地理位置信息
- 根据经纬度获取地理位置名称省、市等信息
- 通过poi获取到了商店的地理位置之后,如何获取商店的详细信息。是需要商店提供还是地图提供
- 通过GeoIP2分析访问者IP获取地理位置信息
- 通过html5获取地理位置信息
- android 通过经纬度获取具体的地理信息
- HTML5获取地理经纬度并通过百度接口得到实时位置
- 通过基站信息(LAC,CID)调用google的json接口获取地理位置信息的Java代码