user1209216
user1209216

Reputation: 7934

Android MapsUtils - pick up location on map click

I'm using android maps utils in my project: https://github.com/googlemaps/android-maps-utils

Works fine, but I'm missing one functionality: I need to pick up position by click on map and save location in my local database.

Do you have any idea how to do that? Scenario: new maps activity shown, after user touch on map I need to add marker on touched position and some event containing coordinates to be able to process them.

Upvotes: 0

Views: 1413

Answers (1)

Komal12
Komal12

Reputation: 3348

Try this,

    googleMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {

        @Override
        public void onMapClick(LatLng point) {
                Bitmap imageBitmap = BitmapFactory.decodeResource(getResources(), getResources().getIdentifier(getResources().getResourceName(R.drawable.pin), "drawable", getPackageName()));
                Bitmap resizedBitmap = Bitmap.createScaledBitmap(imageBitmap, 38, 38, false);

                googleMap.addMarker(new MarkerOptions()
                        .position(new LatLng(point.latitude, point.longitude))
                        .anchor(0.5f, 0.1f)
                        .title("")
                        .snippet("")
                        .icon(BitmapDescriptorFactory.fromBitmap(resizedBitmap)));

            }
        }
    });

Upvotes: 2

Related Questions