Android Maps API v2 Change MyLocation Icon

后端 未结 6 1723
野趣味
野趣味 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:35

    try this; I use this for draw a route on the map, but I set icons for the markers and for my location Declare this for view your location:

        LocationManager locationManager = (LocationManager) 
        getSystemService(LOCATION_SERVICE);
        Criteria criteria = new Criteria();
        String provider = locationManager.getBestProvider(criteria, true);
        Location myLocation= locationManager.getLastKnownLocation(provider);
    
        longitude = myLocation.getLongitude();
        latitude  = myLocation.getLatitude();
        fromPosition = new LatLng(latitude, longitude);
    

    And create a function like that, I used for draw on the map but I set icons on the markers and my position:

    mGoogleMap.clear();
    if(response.equalsIgnoreCase("Success"))
    {
         ArrayList directionPoint = v2GetRouteDirection.getDirection(document);
         PolylineOptions rectLine = new PolylineOptions().width(7).color(Color.BLUE);
    
         for (int i = 0; i < directionPoint.size(); i++) {
         rectLine.add(directionPoint.get(i));
         }
         // Adding route on the map
         mGoogleMap.setOnMarkerClickListener(MainActivity.this);
         mGoogleMap.addPolyline(rectLine);
         markerOptions.position(fromPosition);
         markerOptions.draggable(true);
         Marker1 = mGoogleMap.addMarker(new MarkerOptions()
                   .position(Estadio)
                   .title("Estadio Cuscatlan")
                   .snippet("Estadio Cuscatlan")                                                    
                   .icon(BitmapDescriptorFactory                                          
                   .fromResource(R.drawable.mapmarker))); 
         Marker2 = mGoogleMap.addMarker(new MarkerOptions()
                   .position(Metrocentro)
               .title("Metrocentro")
               .snippet("Metrosuelo")
               .icon(BitmapDescriptorFactory
               .fromResource(R.drawable.mapmark
          Marker3 = mGoogleMap.addMarker(new MarkerOptions()
                .position(Mejicanos)
                .title("Mejicanos")
                .snippet("Mejicanos")
                .icon(BitmapDescriptorFactory
                .fromResource(R.drawable.mapmarker)));  
          MarkerMe = mGoogleMap.addMarker(new MarkerOptions()                                             
                            .position(fromPosition) 
                            .icon(BitmapDescriptorFactory
                            .fromResource(R.drawable.car64)));
       }
        Dialog.dismiss();
        } 
    } 
    

提交回复
热议问题