Android Maps API v2 Change MyLocation Icon

后端 未结 6 1721
野趣味
野趣味 2020-11-27 04:50

I would like to replace the default icon that Android Maps V2 uses for \'My Location\' (The little blue dot/arrow) with my own image. I\'ve created my own tile provide

6条回答
  •  半阙折子戏
    2020-11-27 05:25

    You can not handle click event of MyLocation button on Google map, yeah but there is a trick through which you can get behavior as per your need:
    first in your layout.xml file add map and dummy MyLocation button.
    You can achieve this with the help of Relative Layout:

    
    
        
    
        


    You can take "mylocation.png" seems like u see on Google map.
    LocationManager locationManager = (LocationManager)getSystemService(LOCATION_SERVICE);

        Criteria criteria = new Criteria();
        String s = locationManager.getBestProvider(criteria, false);
    
        Location location = locationManager.getLastKnownLocation(s);  
    

    Call click event of your dummy MyLocation button, in which you will add marker
    private GoogleMap googleMap; googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap(); LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude()); googleMap.addMarker(new MarkerOptions().icon(YOUR_MODIFIED_ICON).position(latLng).title(TITLE).snippet(SNIPET));
    In this way you can modify Google map's default icon.
    Yeah also you need to set zoom level:
    googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));

提交回复
热议问题