Java 类com.google.android.gms.location.places.ui.PlaceSelectionListener 实例源码

项目:Android-WYSIWYG-Editor    文件:MapsActivity.java   
protected synchronized void buildGoogleApiClient() {
    PlaceAutocompleteFragment fragment = (PlaceAutocompleteFragment)
            getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);
    fragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
        @Override
        public void onPlaceSelected(Place place) {
            // Handle the selected Place
            Context context = getApplicationContext();
            CharSequence text = place.getName();
            int duration = Toast.LENGTH_LONG;
            Toast toast = Toast.makeText(context, "Location,"+text+" selected", duration);
            toast.show();
           SelectedLatLng = place.getLatLng();
            mMap.setTrafficEnabled(true);

            CameraPosition cameraPosition = new CameraPosition.Builder()
                    .target(SelectedLatLng)      // Sets the center of the map to Mountain View
                    .zoom(17)                   // Sets the zoom
                    .bearing(90)                // Sets the orientation of the camera to east
                    .tilt(30)                   // Sets the tilt of the camera to 30 degrees
                    .build();                   // Creates a CameraPosition from the builder
            mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));



            mMap.addMarker(new MarkerOptions()
                    .position(SelectedLatLng)
                    .title(text.toString())
                    .icon(BitmapDescriptorFactory.fromResource(R.drawable.map_marker)));
        }

        @Override
        public void onError(Status status) {
            // Handle the error
        }
    });

}