PlacePicker.IntentBuilderは、開いた直後に閉じます

アレンペリー

PlacePicker.IntentBuilderUIをアプリケーションに実装しました。長い間問題なく動作しましたが、UIが表示されるとすぐに閉じて、理由がわかりません。クレイジーなのは、クラッシュしたり例外を引き起こしたりしないlogcatを見ているので、問題が何であるかわかりません。これは、それを作成して呼び出すクラスです。

    package com.example.apthagreat.faf;
    import android.app.AlertDialog;
    import android.content.DialogInterface;
    import android.content.Intent;
    import android.os.AsyncTask;
    import android.support.v7.app.ActionBarActivity;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.Toast;

    import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
    import com.google.android.gms.common.GooglePlayServicesRepairableException;
    import com.google.android.gms.location.places.Place;
    import com.google.android.gms.location.places.ui.PlacePicker;
    import com.google.android.gms.maps.model.LatLng;
    import com.google.android.gms.maps.model.LatLngBounds;

    import org.apache.http.HttpEntity;
    import org.apache.http.HttpResponse;
    import org.apache.http.StatusLine;
    import org.apache.http.client.HttpClient;
    import org.apache.http.client.methods.HttpGet;
    import org.apache.http.impl.client.DefaultHttpClient;
    import org.json.JSONArray;
    import org.json.JSONException;
    import org.json.JSONObject;

    import java.io.BufferedReader;
    import java.io.InputStream;
    import java.io.InputStreamReader;


    public class DetermineSearchCoordinatesScreen extends ActionBarActivity
    {
        //Instance Variables
    int PLACE_PICKER_REQUEST = 1;
    int SELECTED_PLACE_REQUEST = 2;
    LatLng southWestBounds;
    LatLng northEastBounds;
    String zipCodeString;
    String zipCodeURL;
    String user;


    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_determine_search_coordinates_screen);
        final EditText zipCode = (EditText) findViewById(R.id.enterZip);
        final Button findZip = (Button) findViewById(R.id.findZipButton);
        user = getIntent().getExtras().getString("username");
        //Find button is used when user enters a zip code and not the device's GPS
        findZip.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                if (findZip.getText().equals("FIND!"))
                {
                    //build the URL to be passed to determine coordinates for given zip code
                    zipCodeURL = "http://maps.googleapis.com/maps/api/geocode/json?address=";
                    zipCodeString = zipCode.getText().toString();
                    if (zipCodeString.length() == 5)
                    {
                        //Fetch to go get GPS coordinates for zip code
                        zipCodeURL += zipCodeString;
                        GetZipCoordinates task = new GetZipCoordinates(southWestBounds, northEastBounds);
                        task.execute(zipCodeURL);
                        findZip.setText("PUSH TO SEE PLACES");
                    }
                    else
                    {
                        Toast.makeText(getApplicationContext(), "Must enter a valid 5 digit zip code", Toast.LENGTH_SHORT).show();
                    }

                }
                else if (findZip.getText().equals("PUSH TO SEE PLACES"))
                {
                    //AsyncTask was successful in finding coordinates and now we can pass the coordinates in and display places to user
                    PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
                    LatLngBounds llb = new LatLngBounds(southWestBounds, northEastBounds);
                    builder.setLatLngBounds(llb);
                    findZip.setText("FIND!");
                    try
                    {
                        startActivityForResult(builder.build(DetermineSearchCoordinatesScreen.this), PLACE_PICKER_REQUEST);
                    }
                    catch (GooglePlayServicesRepairableException e)
                    {
                        e.printStackTrace();
                    }
                    catch (GooglePlayServicesNotAvailableException e)
                    {
                        e.printStackTrace();
                    }
                    catch(NullPointerException npe)
                    {
                        Toast.makeText(getBaseContext(),"Retrieval of coordinates is not yet complete! Try Again.", Toast.LENGTH_LONG).show();
                    }
                }
            }

        });
        //Here we will use the device's GPS coordinates and display nearby places
        Button currentSpot = (Button) findViewById(R.id.currentLocationButton);
        currentSpot.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
                try
                {
                    startActivityForResult(builder.build(DetermineSearchCoordinatesScreen.this), PLACE_PICKER_REQUEST);
                }
                catch (GooglePlayServicesRepairableException e)
                {
                    e.printStackTrace();
                }
                catch (GooglePlayServicesNotAvailableException e)
                {
                    e.printStackTrace();
                }
            }
        });

    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_search_category_location_screen, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings)
        {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    public void setNorthEastBounds(LatLng northEastBounds)
    {
        this.northEastBounds = northEastBounds;
    }

    public void setSouthWestBounds(LatLng southWestBounds)
    {
        this.southWestBounds = southWestBounds;
    }

    /*
        Once the user selects a place, a dialog will appear prompting the user if they would like
        to create an activity at this place
     */
    protected void onActivityResult(int requestCode, int resultCode, Intent data)
    {
        if (requestCode == PLACE_PICKER_REQUEST)
        {
            if (resultCode == RESULT_OK)
            {
                //The place the user selected
                final Place place = PlacePicker.getPlace(data, this);
                //The dialog that will prompt the user to create an activity when a place is selected
                AlertDialog.Builder createActivity = new AlertDialog.Builder(this);
                createActivity.setMessage("Would you like to create an activity at this location?");
                createActivity.setPositiveButton("YES", new DialogInterface.OnClickListener()
                {
                    @Override
                    public void onClick(DialogInterface dialog, int which)
                    {
                        //Here the user will be directed to the create activity screen and the name and address of selected place will be passed along with it
                        Intent create = new Intent(getApplicationContext(), CreateActivityScreen.class);
                        create.putExtra("username", user);
                        create.putExtra("placeName", place.getName());
                        create.putExtra("placeAddress", place.getAddress());
                        startActivityForResult(create, SELECTED_PLACE_REQUEST);

                        finish();
                    }
                });
                createActivity.setNegativeButton("NO", new DialogInterface.OnClickListener()
                {
                    @Override
                    public void onClick(DialogInterface dialog, int which)
                    {
                        //If the user doesn't want to create an activity nothing will happen
                    }
                });
                createActivity.show();
            }
        }
    }

    /*
        The class that is taking the URL and fetching to the internet to find
        the GPS coordinates for the user given zip code.
        Parses the data into a JSON object and converts it into Latitude and Longitude
        coordinates.
        The coordinates are given in the form of the Southwest bound coordinates and
        Northeast bound coordinates around the zip code.
     */
    private class GetZipCoordinates extends AsyncTask<String, Void, String>
    {
        LatLng sw;
        LatLng ne;

        public GetZipCoordinates(LatLng sw, LatLng ne)
        {
            this.sw = sw;
            this.ne = ne;
        }

        @Override
        protected String doInBackground(String... placesURL)
        {
            //fetch places
            StringBuilder placesBuilder = new StringBuilder();
            //process search parameter string(s)
            for (String placeSearchURL : placesURL)
            {
                //execute search
                HttpClient placesClient = new DefaultHttpClient();
                try
                {
                    //try to fetch the data
                    HttpGet placesGet = new HttpGet(placeSearchURL);
                    HttpResponse placesResponse = placesClient.execute(placesGet);
                    StatusLine placeSearchStatus = placesResponse.getStatusLine();
                    //System.err.println(placeSearchStatus);
                    if (placeSearchStatus.getStatusCode() == 200)
                    {
                        //we have an OK response
                        HttpEntity placesEntity = placesResponse.getEntity();
                        InputStream placesContent = placesEntity.getContent();
                        InputStreamReader placesInput = new InputStreamReader(placesContent);
                        BufferedReader placesReader = new BufferedReader(placesInput);
                        String lineIn;
                        while ((lineIn = placesReader.readLine()) != null)
                        {
                            placesBuilder.append(lineIn);
                        }
                    }
                }
                catch (Exception e)
                {
                    System.err.println("The website is never executed");
                }
            }
            return placesBuilder.toString();
        }

        //Take the results from the URL, separate it, and get the Southwest and Northeast bound coordinates
        protected void onPostExecute(String result)
        {
            LatLng SWBounds = null;
            LatLng NEBounds = null;
            try
            {
                JSONObject resultObject = new JSONObject(result);
                JSONArray placesArray = resultObject.getJSONArray("results");
                try
                {
                    JSONObject placeObject = placesArray.getJSONObject(0);
                    JSONObject southWestLoc = placeObject.getJSONObject("geometry").getJSONObject("bounds").getJSONObject("southwest");
                    JSONObject northEastLoc = placeObject.getJSONObject("geometry").getJSONObject("bounds").getJSONObject("northeast");
                    SWBounds = new LatLng(Double.valueOf(southWestLoc.getString("lat")), Double.valueOf(southWestLoc.getString("lng")));
                    NEBounds = new LatLng(Double.valueOf(northEastLoc.getString("lat")), Double.valueOf(northEastLoc.getString("lng")));
                    setSouthWestBounds(SWBounds);
                    setNorthEastBounds(NEBounds);
                }
                catch (JSONException jse)
                {
                    System.err.println("The bounds were not computed");
                }
            }
            catch (Exception e)
            {
                System.err.println("The JSON object was never read");
            }
        }
    }

    @Override
    public void onPause()
    {
        super.onPause();
        //Blank the URL after the Map is displayed
        zipCodeURL = null;
    }

    @Override
    public void onResume()
    {
        super.onResume();
        //For safe measures, set to blank when activity reappears
        zipCodeURL = "";
    }

}

これは、このクラスにアクセスして、PlacePlace.IntentBuilderを呼び出すボタンを押したときのログキャットです。

04-16 21:19:24.513    7650-7650/com.example.apthagreat.faf D/Activity﹕ performCreate Call debug elastic valuetrue
04-16 21:19:24.683    7650-7671/com.example.apthagreat.faf D/OpenGLRenderer﹕ endAllStagingAnimators on 0x9d2dd000 (RippleDrawable) with handle 0xb4ad4d60
04-16 21:19:24.703    7650-7650/com.example.apthagreat.faf I/Timeline﹕ Timeline: Activity_idle id: android.os.BinderProxy@24ce418b time:4496690
04-16 21:19:24.973    7650-7650/com.example.apthagreat.faf V/ActivityThread﹕ updateVisibility : ActivityRecord{26aa4d14 token=android.os.BinderProxy@1b7217fa {com.example.apthagreat.faf/com.example.apthagreat.faf.ActivityListScreen}} show : false
04-16 21:19:26.633    7650-7650/com.example.apthagreat.faf D/ViewRootImpl﹕ ViewPostImeInputStage ACTION_DOWN
04-16 21:19:26.813    7650-7671/com.example.apthagreat.faf D/OpenGLRenderer﹕ endAllStagingAnimators on 0x9d2e9600 (RippleDrawable) with handle 0x9f64add0
04-16 21:19:27.543    7650-7650/com.example.apthagreat.faf W/IInputConnectionWrapper﹕ showStatusIcon on inactive InputConnection
04-16 21:19:28.143    7650-7650/com.example.apthagreat.faf I/Timeline﹕ Timeline: Activity_idle id: android.os.BinderProxy@24ce418b time:4500135

誰かがこれを手伝ってくれませんか。

CGパターソン

私は同じ問題を抱えていました。開発者コンソール「PlacesAPI」だけでなく「PlacesAPIforAndroid」も有効にしてください「PlacesAPIfor Android」は、(まだ)人気のあるAPIではないため、「API&Auth / API」の下に表示されません。API検索ボックスを使用して検索する必要があります。

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

PlacePickerは、起動するとすぐに閉じます

分類Dev

PlacePicker.getPlace()は廃止されました

分類Dev

ウィジェット画面を開かずにPlacePicker

分類Dev

Python Web Socketは、開いた直後に閉じます

分類Dev

ダイアログは開いた直後に閉じます

分類Dev

Android仮想デバイスは開いた直後に閉じます

分類Dev

Xamarin.Android 型または名前空間名 'PlacePicker' が見つかりませんでした

分類Dev

Dmenuによって起動された特定のプログラムは、開いた直後に閉じます

分類Dev

paramsでexeを起動しますが、プログラムは開いた直後に閉じますか?

分類Dev

PlacePicker doesn't pick up material theme

分類Dev

Android PlacePickerが機能するためにACCESS_FINE_LOCATION権限を必要としないのはなぜですか?

分類Dev

AdMobADビューコントローラーは開いた直後に閉じます

分類Dev

PyQtウィンドウは開いた後に閉じます

分類Dev

PyQt:新しいウィンドウを開いた直後に閉じるのはなぜですか

分類Dev

'Workbook.open'エラー-ファイルを開いた直後にファイルを閉じます

分類Dev

pygameウィンドウを開いた直後に閉じる

分類Dev

開いた直後にJavascript WebSocketが閉じる

分類Dev

PlacePicker activity doesn't call `onActivityResult` when nothing is selected

分類Dev

PlacePicker の呼び出し中の NullPointerException

分類Dev

NSWindowは、閉じて再度開いた後にクラッシュします

分類Dev

SaveFileDialog は、showDialog() を呼び出した直後に自動的に閉じます。

分類Dev

Xcodeは開いた直後にクラッシュします

分類Dev

GooglePlacePickerは起動直後に閉じます

分類Dev

GooglePlacePickerは起動直後に閉じます

分類Dev

Dockerコンテナは起動直後に閉じます

分類Dev

QMainWindowはshow()の直後に閉じます

分類Dev

PowerShellを介してVisualStudio Codeを開き、VSCodeを起動した直後にPowerShellを閉じるにはどうすればよいですか?

分類Dev

SqlConnectionを「開く/閉じる」または開いたままにしますか?

分類Dev

コード1000でネイティブに反応して開いた直後にWebSocketが閉じるのはなぜですか。(iOS)

Related 関連記事

  1. 1

    PlacePickerは、起動するとすぐに閉じます

  2. 2

    PlacePicker.getPlace()は廃止されました

  3. 3

    ウィジェット画面を開かずにPlacePicker

  4. 4

    Python Web Socketは、開いた直後に閉じます

  5. 5

    ダイアログは開いた直後に閉じます

  6. 6

    Android仮想デバイスは開いた直後に閉じます

  7. 7

    Xamarin.Android 型または名前空間名 'PlacePicker' が見つかりませんでした

  8. 8

    Dmenuによって起動された特定のプログラムは、開いた直後に閉じます

  9. 9

    paramsでexeを起動しますが、プログラムは開いた直後に閉じますか?

  10. 10

    PlacePicker doesn't pick up material theme

  11. 11

    Android PlacePickerが機能するためにACCESS_FINE_LOCATION権限を必要としないのはなぜですか?

  12. 12

    AdMobADビューコントローラーは開いた直後に閉じます

  13. 13

    PyQtウィンドウは開いた後に閉じます

  14. 14

    PyQt:新しいウィンドウを開いた直後に閉じるのはなぜですか

  15. 15

    'Workbook.open'エラー-ファイルを開いた直後にファイルを閉じます

  16. 16

    pygameウィンドウを開いた直後に閉じる

  17. 17

    開いた直後にJavascript WebSocketが閉じる

  18. 18

    PlacePicker activity doesn't call `onActivityResult` when nothing is selected

  19. 19

    PlacePicker の呼び出し中の NullPointerException

  20. 20

    NSWindowは、閉じて再度開いた後にクラッシュします

  21. 21

    SaveFileDialog は、showDialog() を呼び出した直後に自動的に閉じます。

  22. 22

    Xcodeは開いた直後にクラッシュします

  23. 23

    GooglePlacePickerは起動直後に閉じます

  24. 24

    GooglePlacePickerは起動直後に閉じます

  25. 25

    Dockerコンテナは起動直後に閉じます

  26. 26

    QMainWindowはshow()の直後に閉じます

  27. 27

    PowerShellを介してVisualStudio Codeを開き、VSCodeを起動した直後にPowerShellを閉じるにはどうすればよいですか?

  28. 28

    SqlConnectionを「開く/閉じる」または開いたままにしますか?

  29. 29

    コード1000でネイティブに反応して開いた直後にWebSocketが閉じるのはなぜですか。(iOS)

ホットタグ

アーカイブ