2

I'm using the Google Maps API v2 for Android, and I want to place a couple of markers on the map. I have the code as following

       @Override
       public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)

       {
        View rootView = inflater.inflate(R.layout.fragment_map, container, false);

        MapFragment fm = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
        map = fm.getMap();
        rootView.findViewById(R.id.map_hybrid).setSelected(true);


        map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
        map.getUiSettings().setCompassEnabled(true);

        CameraPosition cameraPosition = new CameraPosition.Builder()
                                                .target(new LatLng(39.15326,-9.362926))
                                                .zoom(15)
                                                .build();
        MapFragment.newInstance(new GoogleMapOptions()
                        .camera(cameraPosition));

        map.addMarker(new MarkerOptions().position(new LatLng(39.15326,-9.362926))
                .icon(BitmapDescriptorFactory.fromResource(R.drawable.btn_map_home))); 
        while(i < mapInfo.size())
        {
            BitmapDescriptor mapIcon;

            ... changes the resource of the mapIcon accordingly...

            map.addMarker(new MarkerOptions()
                            .draggable(false)
                            .title(((ArrayList<String>) mapInfo.get(i)).get(3))
                            .position(new LatLng(((ArrayList<Double>) mapInfo.get(i)).get(0), ((ArrayList<Double>) mapInfo.get(i)).get(1)))
                            .icon(mapIcon));
            i = i + 1;
        }   

And whenever I zoom in and zoom out, the icons move. I want them to be fixed

EDIT: Images explaining the issue. position of the marker zoomed outposition of the marker zoomed it

tvieira
  • 1,865
  • 3
  • 28
  • 45
  • can you clarify what you mean by "static"? Don't you want the pin to be at certain coordinate? It moves as you zoom in or zoom out because the coordinates in the view are changing – hoomi Aug 22 '14 at 15:20
  • I updated, I want it fixed. Don't change position with zoom in or zoom out. Where can I change that? – tvieira Aug 22 '14 at 15:41
  • 1
    overlay them on top of the map rather than adding them to the map – hoomi Aug 22 '14 at 15:42
  • wasn't that discontinued on api v2? – tvieira Aug 25 '14 at 15:19
  • I tried to do as a GroundOverlay and it didn't work – tvieira Aug 25 '14 at 15:42
  • Be more specific. What behaviour do you want? Markers don't move, they are fixed to specific coordinates. Groundoverlay also doesn't move but it does scale with the map, unlike markers. – Simas Aug 25 '14 at 19:12
  • I want the position of the markers to be fixed to a location, they are moving up when I zoom out and moving down when zoom in, e.g, a marker on a north coast on the map, when zoomed out points to the sea. – tvieira Aug 26 '14 at 09:42
  • Yyou are doing something horribly wrong or are failing to explain it properly. Markers do not move from their specific coordinates. They do **seem** to move if you zoom out map, but that's because the map is scaling, not the marker. – Simas Aug 26 '14 at 14:56
  • Could be a problem with the sat imagery. The buildings don't look square. – danny117 Aug 26 '14 at 19:53
  • Tried the same location, everything worked fine. What device are you using? – Simas Aug 27 '14 at 07:36
  • I tried on a HTC One (M7) and a Galaxy S4, both happened the same thing – tvieira Aug 27 '14 at 12:04
  • Try updating your Google Maps API, or creating a clean project with default markers just to test this. It's hard to say what may be causing it. – Simas Aug 27 '14 at 16:55
  • Were you able to find the solution? I completely understand your problem and facing the same issue. And also i noticed, Google Maps app on android has same behaviour of marker position changing on zoom. However, uber has seem to resolve the issue while showing their car icon. – Mansha Chuttani Mar 30 '18 at 10:14

1 Answers1

0

The most likely problem its the image your using as a marker. You must be really carefull that your custom marker points to the same point that the defaults markers or it will not point to the same point once you zoom out enough.

https://i.stack.imgur.com/QekbY.jpg

if you use something like this:

https://i.stack.imgur.com/nTAtP.png

The most likely result will be a lot of distortion(and it get worse the more you zoom out!)

Hope this helps you!

Nero
  • 194
  • 1
  • 1
  • 11