Now, let's move on to ViewFragment
. We will be using an Intent
class to launch the built-in Google Maps app but with a pin to mark the location the photo was taken at.
The GPS location is already in the Photo
object and we just need to do the following:
Double
variablesIntent
objectIntent
classActivity
passing in the Intent
classOf course, all this takes place inside the class that handles the button clicks for SHOW MAP.
Add the highlighted code that we just discussed to handle what happens when the user clicks on the SHOW MAP button:
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_view, container, false); TextView textView = (TextView) view.findViewById(R.id.textView); Button buttonShowLocation = (Button) view.findViewById(R.id.buttonShowLocation); textView.setText(mCursor.getString(mCursor.getColumnIndex(DataManager.TABLE_ROW_TITLE))); mImageView = (ImageView) view.findViewById(R.id.imageView); mImageView.setImageURI(Uri.parse(mCursor.getString(mCursor.getColumnIndex(DataManager.TABLE_ROW_URI)))); buttonShowLocation.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { double latitude = Double.valueOf(mCursor.getString (mCursor.getColumnIndex(DataManager. TABLE_ROW_LOCATION_LAT))); double longitude = Double.valueOf(mCursor.getString (mCursor.getColumnIndex(DataManager. TABLE_ROW_LOCATION_LONG))); // Create a URI from the latitude and longitude String uri = String.format(Locale.ENGLISH, "geo:%f,%f", latitude, longitude); // Create a Google maps intent Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri)); // Start the maps activity getActivity().startActivity(intent); } }); return view; }
18.116.63.5