Android:Google Maps v2灰色屏幕并获取UnknownHostException以进行地理编码

时间:2014-06-05 11:15:48

标签: android google-maps google-maps-android-api-2 google-geocoding-api

我正在制作应用,其中会生成一些地址,我需要在Google地图上显示这些地址。我会将HttpGet与google API一起用于使用此URL进行地理编码

https://maps.googleapis.com/maps/api/geocode/json?address=my_address&sensor=true_or_false

将myaddress替换为生成的地址。整个过程完美无缺,谷歌地图和地理编码都无法正常工作。地图只显示灰色平铺屏幕,httpGet给出错误如下:

06-05 06:10:15.047: W/System.err(4432): java.net.UnknownHostException: Unable to resolve host "maps.googleapis.com": No address associated with hostname
06-05 06:10:15.077: W/System.err(4432):     at java.net.InetAddress.lookupHostByName(InetAddress.java:424)
06-05 06:10:15.077: W/System.err(4432):     at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
06-05 06:10:15.087: W/System.err(4432):     at java.net.InetAddress.getAllByName(InetAddress.java:214)
06-05 06:10:15.087: W/System.err(4432):     at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
06-05 06:10:15.087: W/System.err(4432):     at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
06-05 06:10:15.097: W/System.err(4432):     at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
06-05 06:10:15.097: W/System.err(4432):     at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
06-05 06:10:15.097: W/System.err(4432):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
06-05 06:10:15.107: W/System.err(4432):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
06-05 06:10:15.107: W/System.err(4432):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
06-05 06:10:15.107: W/System.err(4432):     at com.example.tradeapp.JSONConnectorGet.connectClient(JSONConnectorGet.java:53)
06-05 06:10:15.107: W/System.err(4432):     at com.example.tradeapp.MapViewingActivity$AsyncTaskRunner.doInBackground(MapViewingActivity.java:74)
06-05 06:10:15.107: W/System.err(4432):     at com.example.tradeapp.MapViewingActivity$AsyncTaskRunner.doInBackground(MapViewingActivity.java:1)
06-05 06:10:15.107: W/System.err(4432):     at android.os.AsyncTask$2.call(AsyncTask.java:288)
06-05 06:10:15.107: W/System.err(4432):     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
06-05 06:10:15.107: W/System.err(4432):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
06-05 06:10:15.107: W/System.err(4432):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
06-05 06:10:15.107: W/System.err(4432):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
06-05 06:10:15.107: W/System.err(4432):     at java.lang.Thread.run(Thread.java:841)
06-05 06:10:15.107: W/System.err(4432): Caused by: libcore.io.GaiException: getaddrinfo failed: EAI_NODATA (No address associated with hostname)
06-05 06:10:15.127: W/System.err(4432):     at libcore.io.Posix.getaddrinfo(Native Method)
06-05 06:10:15.127: W/System.err(4432):     at libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java:61)
06-05 06:10:15.127: W/System.err(4432):     at java.net.InetAddress.lookupHostByName(InetAddress.java:405)
06-05 06:10:15.127: W/System.err(4432):     ... 18 more

我没有改变任何东西,现在它没有用。我尝试在控制台中更改Goggle API密钥并重试,结果仍然相同。

我发现我们应该在httpGet中发送API密钥,所以我尝试了

https://maps.googleapis.com/maps/api/geocode/json?address=my_address&sensor=true_or_false&key=my_key

(之前没有网址中的密钥,它工作得很好),但仍然没有结果。

有什么方法可以修复吗?

这是android清单(与它工作时的情况相同,当然API密钥已经更改了几次,但仍然没有结果)

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.tradeapp"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="19" />

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

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:largeHeap="true"
        android:theme="@style/AppTheme" >
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyA4egtZQUMDjJtTOiy94K2CCh22glrZjT0" />

        <activity
            android:name="com.example.tradeapp.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.example.tradeapp.BackendProcessViewingActivity"
            android:label="@string/title_activity_backend_process_viewing"
            android:parentActivityName="com.example.tradeapp.OptionsActivity" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="OptionsActivity" />
        </activity>
        <activity
            android:name="com.example.tradeapp.OptionsActivity"
            android:label="@string/title_activity_options"
            android:parentActivityName="com.example.tradeapp.MainActivity" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="MainActivity" />
        </activity>
        <activity
            android:name="com.example.tradeapp.ShipmentEventFindingActivity"
            android:label="@string/title_activity_shipment_event_finding"
            android:parentActivityName="com.example.tradeapp.ShipmentSearchingActivity" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="ShipmentSearchingActivity" />
        </activity>
        <activity
            android:name="com.example.tradeapp.ShipmentSearchingActivity"
            android:label="@string/title_activity_shipment_searching"
            android:parentActivityName="com.example.tradeapp.OptionsActivity" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.example.tradeapp.OptionsActivity" />
        </activity>



        <activity
            android:name="com.example.tradeapp.MapViewingActivity"
            android:label="@string/title_activity_map_viewing"
            android:parentActivityName="com.example.tradeapp.ShipmentEventFindingActivity" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.example.tradeapp.ShipmentEventFindingActivity" />
        </activity>

    </application>

</manifest>

0 个答案:

没有答案