Ich aktualisiere meine Android App auf Marshmallow 23 zusammen mit den neuesten GoogleMaps V2. Ein Grund dafür ist, dass die neuesten Karten einen .zIndex-Parameter erlauben, mit dem wir den Z-Index von Dingen, die wir auf der Karte zeichnen, festlegen können.Problem mit GoogleMap .zIndex Parameter
Aber mein Problem ist, dass der Compiler es in einigen meiner addMarker-Anweisungen verwendet, aber nicht in anderen.
Im folgenden Code der Compiler-Flags .zIndex sagt Methode nicht lösen kann:
private void addLegMarker(GoogleMap map, double lat, double lon,
String title, String snippet, float bearing)
{
//this method adds the permanent pin to the map and "moves" the arrow representing the target
//following two floats put the pin point exactly on the blue line
float u = (float) 0.2;
float v = (float) 1.0;
//following float center the arrow
float center = (float) 0.5;
//float myRotation = (float) 90.0;
//add the permanent pin to the location...
map.addMarker(new MarkerOptions().position(new LatLng(lat, lon))
.title(title)
.snippet(snippet)
.anchor(u, v))
.setIcon(BitmapDescriptorFactory.fromResource(R.drawable.cpin)
.zIndex(1.0f)
);
if (!(lastArrowMarker == null))
{
lastArrowMarker.remove();
}
String ArrowSnippet = "Last known position of target phone";
lastArrowMarker = map.addMarker(new MarkerOptions()
.position(new LatLng(lat, lon))
.anchor(center, center)
.snippet(ArrowSnippet)
.rotation(bearing)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.smallredarrow)
.zIndex(1.0f)
));
}
Das ist meine build.gradle Datei:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '23.0.3'
useLibrary 'org.apache.http.legacy' //httpClient not supported in 23.
defaultConfig {
applicationId "com.deanblakely.myappname"
minSdkVersion 16
targetSdkVersion 23
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile project(':library')
//compile project(':googleplayservices_lib')
compile files('libs/gson-2.2.4.jar')
compile 'com.android.support:appcompat-v7:23+'
compile 'com.android.support:design:23+'
//compile 'com.google.android.gms:play-services:9.4.0' too big. we just need maps and gcm
compile 'com.google.android.gms:play-services-maps:9.4.0'
compile 'com.google.android.gms:play-services-gcm:9.4.0'
}
jedoch der folgende Code der .zIndex akzeptiert ganz gut:
lastArrowMarker = map.addMarker((new MarkerOptions()
.position(new LatLng(myPos.latitude, myPos.longitude))
.anchor(center, center)
.snippet("Trip End")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.smallblackdot))
.zIndex(1.0f)
Ich bemerkte, dass, wo es markiert wird, das Kartenobjekt ist Als Argument übergeben und wo es gut funktioniert, bezieht sich der Code direkt auf die GoogleMap namens Map, aber ich sehe nicht, wie das von Bedeutung wäre.
Warum akzeptiert der Compiler diesen einen Parameter an einer Stelle und markiert ihn in einer anderen?
Ich sehe nicht einmal eine 'setIcon'-Methode in der' MarkerOptions' -Dokumentation. Wenn Sie das zu "icon" ändern, was passiert? – nasch