我尝试在 Genymotion 模拟器中实现我的项目地理编码,但它不起作用。然而, map 工作得很好。
- Android 构建目标:4.2.2 使用 Google API
- Genymotion:带有 Google Apps 的 Galaxy Nexus 4.2.2
- 并且我已将 google-play-services_lib 添加到我的项目中
我知道了
E/GooglePlayServicesUtil(1954): The Google Play services resources were not found.
Check your project configuration to ensure that the resources are included.
谁有解决办法?谢谢
最佳答案
众所周知,地理编码器在旧设备上(以及在 Genymotion 上,所以我使用了一个适用于所有环境的辅助类)是出了名的不可靠,而且作为一个类(以及结果的准确性)通常存在问题。
您可以使用谷歌地图非常轻松地进行地理定位,
我编写的异步任务首先使用 Geocoder,如果失败则回退到 HttpRequest(使用 volley),位于 https://gist.github.com/selecsosi/6705630。
相关部分:
向
提出请求"http://maps.google.com/maps/api/geocode/json?address=" + URLEncoder.encode(mAddress, "utf-8") + "&ka&sensor=false"
mAddress 是您要搜索的位置。
该请求将返回一个 JSON 对象,您可以像这样解析
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);
}
关于android - 地理编码不起作用 - Genymotion,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19012053/