Android Maps API v2 Zmiana Ikony MyLocation
Chciałbym zastąpić domyślną ikonę, którą Android Maps V2 używa dla "mojej lokalizacji "(mała niebieska kropka/strzałka) moim własnym obrazem. Stworzyłem własną płytkę provider
, która zawiera kilka map, które są głównie niebieskie i jako takie domyślna ikona mojej lokalizacji jest bardzo trudna do zobaczenia. Wcześniej nadpisałbym metodę draw MyLocationOverlay
, ale w nowym api nie ma takiej. Każda pomoc byłaby świetna!
EDIT: potrzebuję również ikony, aby móc obracać, tak samo jak strzała, w zależności od tego, w którą stronę jesteś zwrócony. Więc nie mogę po prostu użyć normalnego marker
: (W zasadzie muszę tylko stworzyć niestandardowy obrazek dla tej strzałki..
Update Witam wszystkich, aktualizacja do Google play umożliwia teraz płaskich markerów i rotacji markerów, co jest dokładnie to, czego potrzebowałem.
7 answers
Moim prostym rozwiązaniem jest wyłączenie "mojej lokalizacji" Mapy Google
I utwórz ImageView na mapie za pomocą my icon, a następnie przechwyć ImageView za pomocą
Onclick and getMyLocation , animateCamera in onClick this.mGoogleMap.getUiSettings().setMyLocationButtonEnabled(false);
this.mGoogleMap.setMyLocationEnabled(true);
.
@Override
public void onClick(final View v) {
Location location = this.mGoogleMap.getMyLocation();
if (location != null) {
LatLng target = new LatLng(location.getLatitude(), location.getLongitude());
CameraPosition position = this.mGoogleMap.getCameraPosition();
Builder builder = new CameraPosition.Builder();
builder.zoom(15);
builder.target(target);
this.mGoogleMap.animateCamera(CameraUpdateFactory.newCameraPosition(builder.build()));
}
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-02-12 06:07:20
Najnowsza aktualizacja usług Google Play pozwala teraz używać "płaskich" znaczników i obracać je, co jest dokładnie tym, czego potrzebowałem. Oto prosta wersja sposobu, w jaki go zaimplementowałem. Prawdopodobnie jest sporo rzeczy, które mogę zrobić, aby zoptymalizować i dostosować animację, ale na razie robi to zadanie. Wszelkie opinie są mile widziane.
Marker mPositionMarker;
GoogleMap mMap;
@Override
public void onLocationChanged(Location location) {
if (location == null)
return;
if (mPositionMarker == null) {
mPositionMarker = mMap.addMarker(new MarkerOptions()
.flat(true)
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.positionIndicator))
.anchor(0.5f, 0.5f)
.position(
new LatLng(location.getLatitude(), location
.getLongitude())));
}
animateMarker(mPositionMarker, location); // Helper method for smooth
// animation
mMap.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(location
.getLatitude(), location.getLongitude())));
}
public void animateMarker(final Marker marker, final Location location) {
final Handler handler = new Handler();
final long start = SystemClock.uptimeMillis();
final LatLng startLatLng = marker.getPosition();
final double startRotation = marker.getRotation();
final long duration = 500;
final Interpolator interpolator = new LinearInterpolator();
handler.post(new Runnable() {
@Override
public void run() {
long elapsed = SystemClock.uptimeMillis() - start;
float t = interpolator.getInterpolation((float) elapsed
/ duration);
double lng = t * location.getLongitude() + (1 - t)
* startLatLng.longitude;
double lat = t * location.getLatitude() + (1 - t)
* startLatLng.latitude;
float rotation = (float) (t * location.getBearing() + (1 - t)
* startRotation);
marker.setPosition(new LatLng(lat, lng));
marker.setRotation(rotation);
if (t < 1.0) {
// Post again 16ms later.
handler.postDelayed(this, 16);
}
}
});
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-10-29 06:56:27
Od wersji 3.1.36 nie można zmienić ikony (czuję, że zmieni się ona w przyszłości, ale patrząc na szybkość implementacji ulepszeń API v2, nie będzie to przed świętami).
Możesz jednak teraz użyć znacznika, ponieważ ma on funkcję setIcon
.
W zasadzie musisz zapomnieć o GoogleMap.setMyLocationEnabled
, ponieważ zawsze pojawi się powyżej. Zamiast tego utworzysz własne LocationClient
i użyjesz lat, long i bearing z Location
, aby zaktualizować Marker
. Dodatkowo dodaj Circle
i użyj dokładności, aby mieć efekt podobny do domyślnej wizualizacji myLocation.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-05-31 12:12:05
Nie możesz obsłużyć zdarzenia kliknięcia przycisku MyLocation na mapie Google, tak, ale istnieje sztuczka, dzięki której możesz uzyskać zachowanie zgodnie z potrzebami: {]}
pierwszy w twoim układzie.plik xml dodaj mapę i atrapa przycisku MyLocation.
Można to osiągnąć za pomocą układu względnego:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="@+id/myLocationButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="@drawable/mylocation" />
</RelativeLayout>
Możesz wziąć " mylocation.png " wygląda jak u zobaczyć na mapie Google.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 markerprivate 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));
W ten sposób można zmodyfikować domyślną ikonę mapy Google.
Tak również musisz ustawić poziom powiększenia:googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-04-11 07:47:01
Spróbuj tego; używam tego do rysowania trasy na mapie, ale ustawiam ikony dla znaczników i dla mojej lokalizacji Zadeklaruj to dla wyświetl swoją lokalizację:
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);
I stworzyć taką funkcję, użyłem do rysowania na mapie, ale ustawiłem ikony na znacznikach i mojej pozycji:
mGoogleMap.clear();
if(response.equalsIgnoreCase("Success"))
{
ArrayList<LatLng> 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();
}
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-09-27 21:00:30
Oto kod dostępu do przycisku lokalizacji:
View mv=findViewById(R.id.map);
View locationButton = ((View) mv.findViewById(Integer.parseInt("1")).getParent()).findViewById(Integer.parseInt("2"));
RelativeLayout.LayoutParams rlp = (RelativeLayout.LayoutParams) locationButton.getLayoutParams();
// position on right bottom
rlp.addRule(RelativeLayout.ALIGN_PARENT_TOP, 0);
rlp.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
rlp.setMargins(0, 180, 180, 0);
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-06-05 11:09:45
Możesz zmienić ikonę bieżącej lokalizacji wykonując:
mMap.addMarker(new MarkerOptions().position(new LatLng(location.getLatitude(), location.getLongitude()))
.title("Current Location")
.snippet(address)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.your_image)));
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-02-12 06:03:04