- 浏览: 257045 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
sunshine_bean:
第四行改进下URL=`svn info |grep &quo ...
linux判断是否需要svn up的脚本 -
leokelly001:
设置请求头,user-agent就行了
android使用豆瓣API出现500错误及解决方法 -
貌似掉线:
txy7121 写道HandlerFactory和AntiCo ...
大谈android安全2——Activity劫持的防范程序 -
txy7121:
HandlerFactory和AntiConstants这两个 ...
大谈android安全2——Activity劫持的防范程序 -
貌似掉线:
hyc_willie 写道关注着你的框架,希望能见到它的发布 ...
androidkit——Android开发框架
使用android的定位服务,需要在manifest文件里增加相应的权限,这里不赘述。
下面是两个类的代码,第一个是activity,完成的功能是获取经纬度,然后提供查询对应的地址的按钮。
第二个是工具类,从经纬度获取到地址。
蛋疼的是,不知道为什么,我都那样写了,获取到的数据还是英文的,而从浏览器上获取到的却是中文的。求解。
下面是获取到的json数据的格式:
纠结了一个小时,在网上转了一大圈之后,才发现应该这样子写:“http://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f&language=zh-CN&sensor=true”。。真的是估计只有经常使用它的人,和它的开发人员,才知道。。貌似文档中也没有提供相关说明。。(这个答案来自:http://gdgzzch.blog.163.com/blog/static/3764045220118354154284/)
没准是你失散多年的兄弟
?
下面是两个类的代码,第一个是activity,完成的功能是获取经纬度,然后提供查询对应的地址的按钮。
第二个是工具类,从经纬度获取到地址。
/* * @(#)LocationActivity.java Project:androidDevices * Date:2012-6-5 * * Copyright (c) 2011 CFuture09, Institute of Software, * Guangdong Ocean University, Zhanjiang, GuangDong, China. * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.sinaapp.msdxblog.android.location; import android.app.Activity; import android.content.Context; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.view.View; import android.widget.Toast; import com.sinaapp.msdxblog.android.R; /** * @author Geek_Soledad (66704238@51uc.com) */ public class LocationActivity extends Activity { private double mLongitude; private double mLatitude; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.location); } public void onButtonClick(View v) { switch (v.getId()) { case R.id.get_location: getLocation(); break; case R.id.query: Toast.makeText(this, LocationUtil.getAddress(mLatitude, mLongitude), 1000) .show(); break; default: break; } } private void getLocation() { LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locationManager.requestLocationUpdates( LocationManager.NETWORK_PROVIDER, 0, 0, new LocationListener() { @Override public void onStatusChanged(String provider, int status, Bundle extras) { } @Override public void onProviderEnabled(String provider) { Toast.makeText(LocationActivity.this, "enable", 1000) .show(); System.out.println("enable"); } @Override public void onProviderDisabled(String provider) { Toast.makeText(LocationActivity.this, "disable", 1000) .show(); System.out.println("disable"); } @Override public void onLocationChanged(Location location) { mLatitude = location.getLatitude(); mLongitude = location.getLongitude(); System.out.println(location.getLatitude()); System.out.println(location.getLongitude()); Toast.makeText(LocationActivity.this, mLatitude + ":" + mLongitude, 1000).show(); } }); } }
/* * @(#)LocationUtil.java Project:androidDevices * Date:2012-6-5 * * Copyright (c) 2011 CFuture09, Institute of Software, * Guangdong Ocean University, Zhanjiang, GuangDong, China. * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.sinaapp.msdxblog.android.location; import java.nio.charset.Charset; import org.json.JSONException; import org.json.JSONObject; import org.json.JSONTokener; import com.sinaapp.msdxblog.androidkit.net.DownloadUtil; /** * @author Geek_Soledad (66704238@51uc.com) */ public class LocationUtil { public static String getAddress(double lat, double lng) { String url = String .format("http://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f&language=CN&sensor=true", lat, lng); System.out.println(url); String result = DownloadUtil.downloadByUrl(url, Charset.defaultCharset()); return jsonSax(result); } private static String jsonSax(String in) { String address = null; try { JSONTokener tokener = new JSONTokener(in); JSONObject results = (JSONObject) tokener.nextValue(); if (!results.getString("status").equals("OK")) { return "无法获取具体地址。"; } System.out.println(results.toString()); JSONObject result = (JSONObject) results.getJSONArray("results") .get(0); address = result.getString("formatted_address"); } catch (JSONException e) { e.printStackTrace(); } return address; } }
蛋疼的是,不知道为什么,我都那样写了,获取到的数据还是英文的,而从浏览器上获取到的却是中文的。求解。
下面是获取到的json数据的格式:
{ "results" : [ { "address_components" : [ { "long_name" : "外环西路", "short_name" : "外环西路", "types" : [ "route" ] }, { "long_name" : "麻章区", "short_name" : "麻章区", "types" : [ "sublocality", "political" ] }, { "long_name" : "湛江", "short_name" : "湛江", "types" : [ "locality", "political" ] }, { "long_name" : "广东省", "short_name" : "广东省", "types" : [ "administrative_area_level_1", "political" ] }, { "long_name" : "中国", "short_name" : "CN", "types" : [ "country", "political" ] } ], "formatted_address" : "中国广东省湛江市麻章区外环西路", "geometry" : { "bounds" : { "northeast" : { "lat" : 21.15437220, "lng" : 110.29786920 }, "southwest" : { "lat" : 21.15323980, "lng" : 110.29655030 } }, "location" : { "lat" : 21.15385030, "lng" : 110.29716670 }, "location_type" : "APPROXIMATE", "viewport" : { "northeast" : { "lat" : 21.15515498029150, "lng" : 110.2985587302915 }, "southwest" : { "lat" : 21.15245701970850, "lng" : 110.2958607697085 } } }, "types" : [ "route" ] }, { "address_components" : [ { "long_name" : "麻章区", "short_name" : "麻章区", "types" : [ "sublocality", "political" ] }, { "long_name" : "湛江", "short_name" : "湛江", "types" : [ "locality", "political" ] }, { "long_name" : "广东省", "short_name" : "广东省", "types" : [ "administrative_area_level_1", "political" ] }, { "long_name" : "中国", "short_name" : "CN", "types" : [ "country", "political" ] } ], "formatted_address" : "中国广东省湛江市麻章区", "geometry" : { "bounds" : { "northeast" : { "lat" : 21.32472990, "lng" : 110.64709280 }, "southwest" : { "lat" : 20.85674290, "lng" : 110.12168620 } }, "location" : { "lat" : 21.2633380, "lng" : 110.33420 }, "location_type" : "APPROXIMATE", "viewport" : { "northeast" : { "lat" : 21.32472990, "lng" : 110.64709280 }, "southwest" : { "lat" : 20.85674290, "lng" : 110.12168620 } } }, "types" : [ "sublocality", "political" ] }, { "address_components" : [ { "long_name" : "湛江", "short_name" : "湛江", "types" : [ "locality", "political" ] }, { "long_name" : "广东省", "short_name" : "广东省", "types" : [ "administrative_area_level_1", "political" ] }, { "long_name" : "中国", "short_name" : "CN", "types" : [ "country", "political" ] } ], "formatted_address" : "中国广东省湛江市", "geometry" : { "bounds" : { "northeast" : { "lat" : 21.95539610, "lng" : 110.97175080 }, "southwest" : { "lat" : 20.2210810, "lng" : 109.66829810 } }, "location" : { "lat" : 21.2707020, "lng" : 110.3593870 }, "location_type" : "APPROXIMATE", "viewport" : { "northeast" : { "lat" : 21.40704480, "lng" : 110.5320740 }, "southwest" : { "lat" : 21.09339670, "lng" : 110.20797730 } } }, "types" : [ "locality", "political" ] }, { "address_components" : [ { "long_name" : "广东省", "short_name" : "广东省", "types" : [ "administrative_area_level_1", "political" ] }, { "long_name" : "中国", "short_name" : "CN", "types" : [ "country", "political" ] } ], "formatted_address" : "中国广东省", "geometry" : { "bounds" : { "northeast" : { "lat" : 25.51677140, "lng" : 117.31808370 }, "southwest" : { "lat" : 20.2210810, "lng" : 109.66829810 } }, "location" : { "lat" : 23.1321910, "lng" : 113.2665310 }, "location_type" : "APPROXIMATE", "viewport" : { "northeast" : { "lat" : 25.51677140, "lng" : 117.31808370 }, "southwest" : { "lat" : 20.2210810, "lng" : 109.66829810 } } }, "types" : [ "administrative_area_level_1", "political" ] }, { "address_components" : [ { "long_name" : "中国", "short_name" : "CN", "types" : [ "country", "political" ] } ], "formatted_address" : "中国", "geometry" : { "bounds" : { "northeast" : { "lat" : 53.56097399999999, "lng" : 134.772810 }, "southwest" : { "lat" : 18.15352160, "lng" : 73.49941369999999 } }, "location" : { "lat" : 35.861660, "lng" : 104.1953970 }, "location_type" : "APPROXIMATE", "viewport" : { "northeast" : { "lat" : 53.56097399999999, "lng" : 134.772810 }, "southwest" : { "lat" : 18.15352160, "lng" : 73.49941369999999 } } }, "types" : [ "country", "political" ] } ], "status" : "OK" }
纠结了一个小时,在网上转了一大圈之后,才发现应该这样子写:“http://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f&language=zh-CN&sensor=true”。。真的是估计只有经常使用它的人,和它的开发人员,才知道。。貌似文档中也没有提供相关说明。。(这个答案来自:http://gdgzzch.blog.163.com/blog/static/3764045220118354154284/)
评论
4 楼
貌似掉线
2013-04-08
xiaozhi6156 写道
一看,差点以为1楼是我呢..- -!
没准是你失散多年的兄弟
3 楼
xiaozhi6156
2013-04-07
一看,差点以为1楼是我呢..- -!
2 楼
貌似掉线
2012-06-08
xiaoxin0424 写道
没仔细看文档的结果
?
1 楼
xiaoxin0424
2012-06-06
没仔细看文档的结果
发表评论
-
利用电脑玩Android版“天天连萌”刷高分(四)——模拟按键及程序优化
2014-01-22 00:14 1664这一系列文章,没想到从去年10月份以来,写了三篇我就忘了写了, ... -
利用电脑玩Android版“天天连萌”刷高分(三)——连连看消除搜索
2013-10-29 17:02 1145差点忘了写接下来的这两篇博客了,这篇如果接不上上一篇,请勿见怪 ... -
利用电脑玩Android版“天天连萌”刷高分(二)——图像识别
2013-10-20 15:44 1490上一篇只是提到了在PC端利用android sdk里面的工具进 ... -
利用电脑玩Android版“天天连萌”刷高分(一)——截图
2013-10-20 11:22 3378这几周微信游戏“天天 ... -
在PC端进行android截屏的多种方法
2013-10-18 11:01 3541昨晚意外的发现在PC端进行截屏的方法相当多,在android ... -
近期计划
2013-09-01 20:02 1193在上一篇(http://maosidiao ... -
Android开源游戏引擎之Angle(二)——开始前的准备
2013-09-01 12:04 2430在上一篇博客(http://mao ... -
Android开源游戏引擎之Angle(一)——概述
2013-08-31 19:26 5967Angle是一个Android平台上 ... -
设置tabWidget标题的字体大小及颜色
2013-03-27 13:47 9400/* * @(#)TextAppearenceUtil ... -
桌面小部件AppWidget的使用
2013-02-23 13:49 1683在android平台中,显示在HOME界面的一些挂件,即桌面小 ... -
android使用actionbar与fragment
2013-01-16 23:12 2258android使用actionbar中的tab,及fragme ... -
android使用豆瓣API出现500错误及解决方法
2013-01-10 18:56 6188为团队做一个图书管理的应用,涉及到扫描ISBN然后查询图书信息 ... -
进入程序的动画IntroActivity增强版
2012-12-11 10:19 1442这是对上一次谈到的android程序进入前的动画的封装(详见: ... -
androidkit发布0.5.3alpha版
2012-12-07 09:26 1198androidkit是一个用于android应用层开发的工具包 ... -
使用Zxing及豆瓣API
2012-12-06 20:30 2364本文原创,转载请注明原文地址:http://maosidiao ... -
androidkit——减少android开发代码的工具包
2012-11-16 22:25 2193androidkit是我学android开发以来,慢慢在封装的 ... -
android开发知识点1——按钮效果
2012-10-30 15:15 2294android中控件的背景或ImageView、ImageBu ... -
android颜色选择器
2012-09-24 13:39 3313前段时间想到要封装一个颜色选择器的类,查询后知道谷歌api d ... -
androidt程序文字锯齿
2012-09-24 00:51 1253刚才才发现,在开发android程序时,如果在manifest ... -
大谈android安全2——Activity劫持的防范程序
2012-09-23 23:13 9308本文原创,转载请注明出处: http://maosidiaox ...
相关推荐
eclipse项目。获取raw文件下的json文件。无需编写json数据里面key值的实体类,动态获取里面的键值对的值。并在列表显示
本文实例讲述了Android读取本地json文件的方法。分享给大家供大家参考,具体如下: 1、读取本地JSON ,但是显示汉字乱码 public static String readLocalJson(Context context, String fileName){ String json...
最近在整理自己写过的一些应用,发现这个也许对大家有帮助,android通过http页面获取json标准格式数据并且解析其中对象的全过程,其中包含android连接http页面方法,android解析json格式数据方法,json标准化格式...
首先客户端从服务器端获取json数据 1、利用HttpUrlConnection 代码如下:/** * 从指定的URL中获取数组 * @param urlPath * @return * @throws Exception */ public static String readParse(String urlPath) ...
在模块对应的包名下创建JSON数据对应的实体类WeatherInfo类,实体类中的成员名称要与JSON数组的key值一致,并为每个属性添加get和set方法。public String getTemp() {return temp;}public void setTemp(String temp)...
1. 例子代码有两部分:androidJson是andoird的工程,inxdex.php是php服务器json数据产生部分代码。 2. 服务器端提供http(get)获取方式获取json数据的api例子,是用php写的。 4. android的apk给你说完成http数据...
android客户端从服务器端获取json数据并解析
适合新手参考,简单实用,因为我也是新手,所以用的都是比较基础的方法实现。...okhttp方法获取服务器JSON数据或者获取本地android studio内的txt文本解析,然后显示在listview上,listview增加了上滑加载更多的功能
http连接 获取json 解析json 显示json数据 Springboot服务器
从网络获取解析json的android demo
【Android 开发】: Android客户端与服务端之间使用JSON交互数据。 http://blog.csdn.net/ahuier/article/details/15493603 客户端代码
利用豆瓣API V2.0 ISBN码 获取书籍的相关信息,未采用控件获取https的网络数据,得到JOSN的返回数据后进行解析。
Android 实用的数据json数据解析封装类,能快速解析任何形式json数据
利用GET请求获取到JSON数据,然后再Android Studio中对JSON数组进行解析,获取到的内容展示再ListView上,比较适合萌新学习解析JSON数组,每一个步骤都有注释,非常的详细。
android 单排显示gridview并从解析JSON读取数据加载项目.zip
android json 解析 json数据格式解析我自己分为两种; 一种是普通的,一种是带有数组形式的;
本文主要讲解,通过HttpURLConnection从服务端获取数据,然后经过JSON解析后,显示在手机屏幕上。
android天气预报通过网络读取数据并解析JSON。需要用到JSONObject
Android高级应用源码-通过httpclient获取到JSON数据,展示到ListView.zip