问题描述
我试图在Genymotion模拟器中实现我的项目地址编码,但是它不起作用.但是,该地图可以完美运行.
I've tried to implement my project geocode in Genymotion emulator, but it doesn't work. However the map works perfectly.
- Android构建目标:4.2.2使用Google API
- Genymotion:具有Google Apps的Galaxy Nexus 4.2.2
- 并且我已经将google-play-services_lib添加到我的项目中
我有这个
有人有解决方案吗?谢谢
anyone have a solutions? Thanks
推荐答案
地理编码是旧设备上的极不可靠(以及上Genymotion所以我使用一个辅助类,在所有enviornments作品),以及有问题的一般为一个类(以及结果的准确性).
The geocoder is notoriously unreliable on older devices (as well as on Genymotion so I use a helper class that works in all enviornments) as well as problematic in general as a class (and accuracy of results).
您可以使用Google地图非常轻松地进行地理位置定位,
You can use google maps to do geolocation very easily,
我编写的一个异步任务首先使用Geocoder,如果失败则回退到HttpRequest(使用截击),位于https://gist.github.com/selecsosi/6705630
An asynctask I wrote to use Geocoder first and fallback to a HttpRequest (using volley) if that fails is at https://gist.github.com/selecsosi/6705630
相关部分:
请求
"http://maps.google.com/maps/api/geocode/json?address=" + URLEncoder.encode(mAddress, "utf-8") + "&ka&sensor=false"
使用mAddress作为您要搜索的位置.
with mAddress being the location you are searching for.
该请求将返回一个JSON对象,您可以像这样解析
That request will return you a JSON object you can parse like so
public static LatLng getLatLngFromGoogleJson(JSONObject jsonObject) {
double lon = 0d;
double lat = 0d;
try {
lon = ((JSONArray)jsonObject.get("results")).getJSONObject(0)
.getJSONObject("geometry").getJSONObject("location")
.getDouble("lng");
lat = ((JSONArray)jsonObject.get("results")).getJSONObject(0)
.getJSONObject("geometry").getJSONObject("location")
.getDouble("lat");
} catch (JSONException e) {
if(Log.isLoggable(TAG, Log.ERROR))Log.e(TAG, "Error parsing google response", e);
}
return new LatLng(lat, lon);
}
这篇关于地理编码不起作用-Genymotion的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!