地理编码器返回超时错误

时间:2016-01-15 15:03:44

标签: android google-geocoder geocode

我创建了一个函数,通过获取真实地址返回我的地理坐标。直到今天代码工作正常,但从早上起我得到以下异常:

  

等待服务器响应的超时

这是我的功能:

 public LatLng getLocationFromAddress(String strAddress) {
    Geocoder coder = new Geocoder(frag.getActivity());
    List<Address> address;
    LatLng p1 = null;

    try {
        address = coder.getFromLocationName(strAddress,1);
        if (address == null) {
            return null;
        }
        Address location = address.get(0);
        location.getLatitude();
        location.getLongitude();
        p1 = new LatLng(location.getLatitude(), location.getLongitude() );
        Log.d("coordinates",p1.latitude+""+p1.longitude);

    } catch (Exception ex) {
        Log.d("Location Exception", "error converting address");
        ex.printStackTrace();
        Log.d("exception message",ex.getMessage());
    }

    return p1;
}

这是我的清单文件:

    <permission
        android:name="com.example.matant.gpsportclient.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="android.permission.INTERNET" />

    <!-- GCM requires a Google account. -->
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <!--
 The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
         Google Maps Android API v2, but are recommended.
    -->


    <!-- Keeps the processor from sleeping when a message is received. -->
    <uses-permission android:name="android.permission.WAKE_LOCK" />

    <!-- Permission to vibrate -->
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.MANAGE_DOCUMENTS" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
    <uses-permission android:name="com.example.matant.gpsportclient.permission.MAPS_RECEIVE" />

    <android:uses-permission android:name="android.permission.READ_PHONE_STATE" />

    <!-- Creates a custom permission so only this app can receive its messages. -->
    <permission
        android:name="com.example.matant.gpsportclient.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />

<uses-permission android:name="com.galaxystech.pushnotifications.permission.C2D_MESSAGE" />

<!-- This app has permission to register and receive data message. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

<!-- Network State Permissions to detect Internet status -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

0 个答案:

没有答案