Using Map View to Display Location of Clicked Image in Phimpme
Previously in Phimpme Android app we used to display all the images on the map, based on their location they have taken. In the upcoming version, we are introducing mapview to specify the location when user checks out the details of the image. In this post, I am explaining that how I have implemented Google’s mapView in Phimpme. Note: The prerequisite to display image location in the map view, an image should have geolocation in its meta data.
Let’s get started
Step -1 : First, enable the setting to ‘Show mapview in Image description’ and save it somewhere.
Although, it’s your choice you want to give users choice to view map or not.
First, we need to turn on the movie visibility from map provider in settings. Right now we are adding two maps in our list Google maps and openstreetmap.
Choose Map Provider from the list in Phimpme
Once you choose your preference, it will get stored in sharedPref. As we are displaying the map in the image details so we need to add Image view of map.
Step -2 : Add a ImageView in your XML, in which we will display map.
<ImageView android:id="@+id/photo_map" android:layout_width="match_parent" android:layout_height="150dp" android:visibility="gone" />
Keep default visibility of mapview is GONE, If a user will enable map view in setting then we will make this image visible.
Step -3 : Load image with map in ImageView:
Good things are that StaticMapProvier gives you the URL of the image in corresponding to particular GeoLocation, which actually is a view of the map.
Now we need to display mapview when the user taps on details of an image.
ImageView imgMap = (ImageView) dialogLayout.findViewById(R.id.photo_map); final GeoLocation location; if ((location = f.getGeoLocation()) != null) { PreferenceUtil SP = PreferenceUtil.getInstance(activity.getApplicationContext()); StaticMapProvider staticMapProvider = StaticMapProvider.fromValue( SP.getInt(activity.getString(R.string.preference_map_provider), StaticMapProvider.GOOGLE_MAPS.getValue())); Glide.with(activity.getApplicationContext()) .load(staticMapProvider.getUrl(location)) .asBitmap() .centerCrop() .animate(R.anim.fade_in) .into(imgMap);
To load an image, we used Glide Image library, you can use any library of your choice.
MapView on the top of dialog box in Phimpme
Step 4: Open navigation on the tap of mapView or Image.
Attach a click listener on the imageView and on click of that create a Uri correspond to geolocation and through an Intent to Android to view that link, it will open Google maps with navigation.
String uri = String.format(Locale.ENGLISH, "geo:%f,%f?z=%d", location.getLatitude(), location.getLongitude(), 17); activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(uri)));
Resources
- How to display map in static imageview : https://stackoverflow.com/questions/5324004/how-to-display-static-google-map-on-android-imageview
- Displaying location address : https://developer.android.com/training/location/display-address.html
You must be logged in to post a comment.