2016-08-24 2 views
1

Android 앱을 최신 GoogleMaps V2와 함께 Marshmallow 23으로 업그레이드하고 있습니다. 내가 한 이유 중 하나는 최신지도가 .zIndex 매개 변수를 허용하기 때문에지도에 그릴 물건의 Z- 색인을 설정할 수 있기 때문입니다.GoogleMap .z 인덱스 매개 변수와 관련된 문제

하지만 내 문제는 컴파일러가 일부 addMarker 문에서 사용할 수 있지만 다른 문안에서는 사용할 수 없다는 것입니다. 그러나이 다음 코드는 .zIndex 받아들이

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' 

} 

: 이것은 내 build.gradle 파일이

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) 
        )); 

} 

입니다 : 다음 코드에서

컴파일러 플래그 .zIndex 방법을 해결할 수없는 말 그냥 괜찮습니다 :

플래그가 지정되는 곳에서지도 개체가 인수로 전달되고 잘 작동하는 경우 코드는지도라는 GoogleMap을 직접 참조하지만 이것이 중요한지는 알 수 없습니다.

컴파일러가이 매개 변수를 한 곳에서 받아들이고 다른 곳에서 플래그를 지정하는 이유는 무엇입니까?

+0

나는'MarkerOptions' 문서에서'setIcon' 메소드를 보지 못했습니다. 아이콘을'아이콘'으로 변경하면 어떻게됩니까? – nasch

답변

1

MarkerOptions 클래스 has a zIndex() method 그러나 Marker 클래스 has a setZIndex() method.

GoogleMap.addMarker() 메서드는 MarkerOptions 개체 (빌더)에서 Marker 개체를 반환하며 이로 인해 혼동이 생깁니다.

작동하지 않는 경우 Marker 개체에서 setZIndex() 대신 zIndex()을 호출해야합니다.

+0

감사합니다 antonio, 그게 문제였습니다. –

0

== 대신 equals()을 사용해주세요. 리스너의 콜백 것,

이벤트가지도에 마커 중 하나에서 발생

나는 실제로 그것을 시도하지 않은 조금 이상한 해결책이 될 것처럼 보일 수 있지만 Handle marker events에서 언급 한 바와 같이 해당 Marker 객체가 매개 변수로 전달되어 호출 될 수 있습니다. 이 Marker 개체를 Marker 개체에 대한 참조와 비교하려면 을 사용해야하며 ==이 아닌 equals()를 사용해야합니다.

+0

제 생각에 .equals는 문자열 비교를위한 것입니다. == null은 잘 동작합니다. –