地理code不起作用 - Genymotion [英] Geocode doesn't work - Genymotion

查看:176
本文介绍了地理code不起作用 - Genymotion的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图实现我的项目的地缘code在Genymotion模拟器,但它不工作。但是在地图完美的作品。

I've tried to implement my project geocode in Genymotion emulator, but it doesn't work. However the map works perfectly.

  1. 在Android的构建目标:4.2.2与谷歌API
  2. Genymotion:Galaxy Nexus的4.2.2随着谷歌企业应用套件
  3. 我已经添加了谷歌播放的,services_lib到我的项目

我这有

E / GooglePlayServicesUtil(1954年):在谷歌播放均未发现服务资源
  检查项目配置,以确保资源被包括在内。

E/GooglePlayServicesUtil(1954): The Google Play services resources were not found.
Check your project configuration to ensure that the resources are included.

任何人有一个解决方案?谢谢

anyone have a solutions? Thanks

推荐答案

在地理codeR是非常不可靠的旧设备(以及对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).

您可以使用谷歌地图做的地理位置很容易,

You can use google maps to do geolocation very easily,

这是AsyncTask的我写的第一次使用地理coder和退到Htt的prequest(使用抽射),如果失败是的 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);
}

这篇关于地理code不起作用 - Genymotion的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆