Java Code Examples for com.google.android.gms.location.places.Place#getLatLng()

The following examples show how to use com.google.android.gms.location.places.Place#getLatLng() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SearchPlaceOnMapActivity.java    From Airbnb-Android-Google-Map-View with MIT License 5 votes vote down vote up
@Override
public void onResult(PlaceBuffer places) {
    if (!places.getStatus().isSuccess()) {
        places.release();
        return;
    }
    // Get the Place object from the buffer.
    final Place place = places.get(0);
    hideKeyboard();
    mLatitude=String.valueOf(place.getLatLng().latitude);
    mLongitude=String.valueOf(place.getLatLng().longitude);
    LatLng newLatLngTemp = new LatLng(place.getLatLng().latitude, place.getLatLng().longitude);
    // LatLng centerLatLng=new LatLng(mMap.getCameraPosition().target.latitude,mMap.getCameraPosition().target.longitude);
    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(newLatLngTemp, 15f));
}
 
Example 2
Source File: MainActivity.java    From Locate-driver with GNU General Public License v3.0 5 votes vote down vote up
private void setPlace(Place place) {
    if (place == null) {
        this.place = null;
    } else {
        this.place = new LDPlace(place.getName() + "", place.getId(), place.getLatLng().latitude, place.getLatLng().longitude);
    }

    this.saveData();
}
 
Example 3
Source File: Note.java    From memoir with Apache License 2.0 4 votes vote down vote up
public void setLocation(Place place) {
    location = new Location(place.getName().toString(), place.getLatLng().latitude, place.getLatLng().longitude);
}
 
Example 4
Source File: SettingsActivity.java    From Advanced_Android_Development with Apache License 2.0 4 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // Check to see if the result is from our Place Picker intent
    if (requestCode == PLACE_PICKER_REQUEST) {
        // Make sure the request was successful
        if (resultCode == RESULT_OK) {
            Place place = PlacePicker.getPlace(data, this);
            String address = place.getAddress().toString();
            LatLng latLong = place.getLatLng();

            // If the provided place doesn't have an address, we'll form a display-friendly
            // string from the latlng values.
            if (TextUtils.isEmpty(address)) {
                address = String.format("(%.2f, %.2f)",latLong.latitude, latLong.longitude);
            }

            SharedPreferences sharedPreferences =
                    PreferenceManager.getDefaultSharedPreferences(this);
            SharedPreferences.Editor editor = sharedPreferences.edit();
            editor.putString(getString(R.string.pref_location_key), address);

            // Also store the latitude and longitude so that we can use these to get a precise
            // result from our weather service. We cannot expect the weather service to
            // understand addresses that Google formats.
            editor.putFloat(getString(R.string.pref_location_latitude),
                    (float) latLong.latitude);
            editor.putFloat(getString(R.string.pref_location_longitude),
                    (float) latLong.longitude);
            editor.commit();

            // Tell the SyncAdapter that we've changed the location, so that we can update
            // our UI with new values. We need to do this manually because we are responding
            // to the PlacePicker widget result here instead of allowing the
            // LocationEditTextPreference to handle these changes and invoke our callbacks.
            Preference locationPreference = findPreference(getString(R.string.pref_location_key));
            setPreferenceSummary(locationPreference, address);

            // Add attributions for our new PlacePicker location.
            if (mAttribution != null) {
                mAttribution.setVisibility(View.VISIBLE);
            } else {
                // For pre-Honeycomb devices, we cannot add a footer, so we will use a snackbar
                View rootView = findViewById(android.R.id.content);
                Snackbar.make(rootView, getString(R.string.attribution_text),
                        Snackbar.LENGTH_LONG).show();
            }

            Utility.resetLocationStatus(this);
            SunshineSyncAdapter.syncImmediately(this);
        }
    } else {
        super.onActivityResult(requestCode, resultCode, data);
    }
}
 
Example 5
Source File: SettingsFragment.java    From BackPackTrackII with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == ACTIVITY_PICKPLACE && resultCode == Activity.RESULT_OK) {
        Place place = PlacePicker.getPlace(getActivity(), data);
        final CharSequence name = place.getName();
        LatLng ll = place.getLatLng();
        if (name == null || ll == null)
            return;

        // Build location
        final Location location = new Location("place");
        location.setLatitude(ll.latitude);
        location.setLongitude(ll.longitude);
        location.setTime(System.currentTimeMillis());

        // Get settings
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
        final boolean altitude_waypoint = prefs.getBoolean(PREF_ALTITUDE_WAYPOINT, DEFAULT_ALTITUDE_WAYPOINT);

        new AsyncTask<Object, Object, Object>() {
            protected Object doInBackground(Object... params) {
                int altitude_type = (location.hasAltitude() ? BackgroundService.ALTITUDE_GPS : BackgroundService.ALTITUDE_NONE);

                // Add elevation data
                if (!location.hasAltitude() && Util.isConnected(getActivity())) {
                    if (altitude_waypoint)
                        try {
                            GoogleElevationApi.getElevation(location, getActivity());
                            altitude_type = BackgroundService.ALTITUDE_LOOKUP;
                        } catch (Throwable ex) {
                            Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                        }
                }

                if (altitude_type != BackgroundService.ALTITUDE_NONE)
                    altitude_type |= BackgroundService.ALTITUDE_KEEP;

                // Persist location
                new DatabaseHelper(getActivity()).insertLocation(location, altitude_type, name.toString()).close();
                return null;
            }

            @Override
            protected void onPostExecute(Object result) {
                if (running)
                    Toast.makeText(getActivity(), getString(R.string.msg_added, name.toString()), Toast.LENGTH_SHORT).show();
            }
        }.execute();

    } else if (requestCode == ACTIVITY_PLAY_SERVICES)
        ; // Do nothing

    else
        super.onActivityResult(requestCode, resultCode, data);
}