1

我正在使用以下代码从 Google 下载数据并在我的 monodroid 应用程序中获取位置关键字 lat lng:

public  LatLng  GetLatLng (String input)
    {
        HttpURLConnection conn = null;
        StringBuilder jsonResults = new StringBuilder ();
        LatLng gp = null;
        string str = null;
        try {
            StringBuilder sb = new StringBuilder (GEOCODER_API_BASE + OUT_JSON);
            sb.Append ("?address=" + input + "&sensor=true");
            /// "http://maps.googleapis.com/maps/api/geocode/json?address=Paris&sensor=true"
            URL url = new URL (sb.ToString ());
            conn = (HttpURLConnection)url.OpenConnection ();
            Java.IO.InputStreamReader inp = new Java.IO.InputStreamReader (conn.InputStream);

            // Load the results into a StringBuilder
            int read;
            char[] buff = new char[1024];
            while ((read = inp.Read (buff)) != -1) {
                jsonResults.Append (buff, 0, read);
            }
            str = jsonResults .ToString();



        } catch (System.IO.IOException e) {
            RltLog .HandleException (e, "\nError connecting to Places API\n");
            return gp;
        } finally {
            if (conn != null) {
                conn.Disconnect ();
            }
        }
        try {
            // Create a JSON object hierarchy from the results

            JObject address = JObject .Parse (str);            
            JArray ja = (JArray)address ["results"];

            JObject LocationJObejct = (JObject)ja [0] ["geometry"] ["location"];
            gp = HelperMethods .executeLocationPoint (LocationJObejct ["lat"].ToString (),
                                               LocationJObejct ["lng"].ToString ());


        } catch (Exception e) {
            RltLog .HandleException (e);
        }
        return gp;
    }

但我不断收到这些错误:

 Exception of type 'Java.IO.FileNotFoundException' was thrown. 

我想知道是什么原因?

4

1 回答 1

2

You should replace spaces with + in your request based on the google docs.

于 2013-10-12T10:36:59.083 回答