Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Map API V2 - How do I keep a marker in the center of the screen while user is scrolling the map?

Tags:

Google Map API V2 - How do I keep a marker in the center of the screen while user is scrolling the map ?

My purpose is to let user choose a location. I use the following code to add a marker (it's from the com.example.mapdemo in Android SDK)

mMap.addMarker(new MarkerOptions()
    .position(new LatLng(0, 0))
    .title("Marker"));

How do I keep the marker in the center of the screen and then retrieve it's location?

like image 208
dong221 Avatar asked Jan 04 '13 06:01

dong221


People also ask

How do I get a marker position on Google Maps?

You can add a simple marker to the map at a desired location by instantiating the marker class and specifying the position to be marked using latlng, as shown below.

How do you move a marker in maps?

Use a long press to activate the ability to move the marker. By default, when a user taps a marker, the map toolbar appears at the bottom right of the map, giving the user quick access to the Google Maps mobile app.

How do I move a marker smoothly on Google Maps?

The transition() and moveMarker() are used to move marker smoothly on click on the Google map.


2 Answers

I do not think that you can actually keep a marker in the middle of the screen and float it easily. My suggestion is to trick your user. Add your marker image onto the map like a button. you can place it in the middle of the screen using the xml layout. Then when your user selects a location just retrieve the gps coordinates from the middle of the screen.

On a side note you could also just make your marker draggable Then the user could drag it around the map.

mMap.addMarker(new MarkerOptions().position(coordinate)
                    .title("Your Title")
                    .snippet("Please move the marker if needed.")
                    .draggable(true)); 
like image 72
doubleA Avatar answered Oct 21 '22 12:10

doubleA


How about?

mMap.setOnCameraChangeListener(new OnCameraChangeListener() {
        public void onCameraChange(CameraPosition arg0) {   
                mMap.clear();               
                mMap.addMarker(new MarkerOptions().position(arg0.target));
        }
});
like image 37
Akexorcist Avatar answered Oct 21 '22 12:10

Akexorcist