2016-03-22 17 views
1

Harita merkezinin çokgenin içinde olup olmadığını kontrol etmeye çalışıyorum. Harita merkezi herhangi çokgen içinde olup olmadığınıİçerisinde Latlng aranıyor Çokgen hassas değil

map.setOnCameraChangeListener(new OnCameraChangeListener() { 
     @Override 
     public void onCameraChange(CameraPosition cameraPosition) { 
        if (arr_ltlngbounds != null && arr_ltlngbounds.size() > 0) { 
         for (LatLngBounds l : arr_ltlngbounds) { 
          if (l.contains(mMap.getCameraPosition().target)) { 

           snackbar = Snackbar 
             .make(inflatedView, "Service available here", Snackbar.LENGTH_INDEFINITE) 
             .setAction("GET", new View.OnClickListener() { 
              @Override 
              public void onClick(View view) { 
               String arr[] = {user_location.latitude + "", user_location.longitude + "", "4"}; 
               new Get_service(activity, A.this, get_service).execute(arr); 
              } 
             }); 
           snackbar.show(); 
           break; 
         } 
        } 
      } 
     } 
    }); 

Bu benim build.gradle sadece örtmek

apply plugin: 'com.android.application' 

android { 
compileSdkVersion 23 
buildToolsVersion "22.0.1" 

defaultConfig { 
    multiDexEnabled true 
    applicationId "com.aaa.bbb" 
    minSdkVersion 14 
    targetSdkVersion 23 
    compileOptions { 
     sourceCompatibility JavaVersion.VERSION_1_7 
     targetCompatibility JavaVersion.VERSION_1_7 
    } 
} 

buildTypes { 
    release { 
     minifyEnabled false 
     proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
    } 
} 
compileOptions { 
    sourceCompatibility JavaVersion.VERSION_1_7 
    targetCompatibility JavaVersion.VERSION_1_7 
} 
} 

dependencies { 
compile project(':library') 
compile 'com.android.support:appcompat-v7:23.1.0' 
compile fileTree(include: ['*.jar'], dir: 'libs') 
compile 'com.android.support:design:23.2.0' 
compile 'com.android.support:recyclerview-v7:23.1.0' 
compile 'com.newrelic.agent.android:android-agent:5.3.1' 
compile 'com.github.bumptech.glide:glide:3.6.1' 
compile 'com.android.support:cardview-v7:23.1.0' 
compile 'com.github.jaydeepw:poly-picker:v1.0.22' 
compile 'com.xgc1986.android:parallaxpagertransformer:1.0.3' 
compile 'com.google.code.gson:gson:2.6.2' 
compile 'me.dm7.barcodescanner:zxing:1.8.4' 
compile 'com.github.castorflex.smoothprogressbar:library:1.0.0' 
compile 'com.github.clans:fab:1.6.2' 
compile 'com.google.android.gms:play-services:8.3.0' 
compile 'com.google.maps.android:android-maps-utils:0.4+' 
compile('com.google.api-client:google-api-client-android:1.20.0') { 
    exclude group: 'org.apache.httpcomponents' 
} 
compile('com.google.apis:google-api-services-drive:v3-rev6-1.20.0') { 
    exclude group: 'org.apache.httpcomponents' 
} 


} 
buildscript { 
repositories { 
    mavenCentral() 
} 
dependencies { 
    classpath "com.newrelic.agent.android:agent-gradle-plugin:5.3.1" 
} 

} 

repositories { 
mavenCentral() 
// for downloading polypicker dependency cwac-camera 
maven { 
    url "https://repo.commonsware.com.s3.amazonaws.com" 
} 

// for downloading poly-picker now we are using jitpack. 
// Goodbye Maven Central 
maven { 
    url "https://jitpack.io" 
} 
} 

apply plugin: 'android' 
apply plugin: 'newrelic' 


dependencies { 
compile 'com.android.support:support-v4:22.2.1' 
} 
android { 
useLibrary 'org.apache.http.legacy' 
} 
olup olmadığını kontrol ediyorum

for (int i = 0; i < Constant.arr_zone.size(); i++) { 
      LatLngBounds.Builder builder = new LatLngBounds.Builder(); 
      ArrayList<LatLng> list = new ArrayList<>(); 
      for (int j = 0; j < Constant.arr_zone.get(i).polygon.length; j++) { 
       list.add(new LatLng(Constant.arr_zone.get(i).polygon[j].geo_x, 
         Constant.arr_zone.get(i).polygon[j].geo_y)); 
       builder.include(list.get(j)); 

      } 
      polygonOptions = new PolygonOptions(); 
      polygonOptions.addAll(list); 
      polygonOptions.strokeColor(R.color.theme_color); 
      polygonOptions.strokeWidth(2); 
      polygonOptions.fillColor(Color.parseColor("#33000040")); 
      Polygon polygon = mMap.addPolygon(polygonOptions); 
      ltbounds = builder.build(); 
      arr_ltlngbounds.add(ltbounds); 
     } 

Sonraki: Harita üzerinde mulitple poligon oluşturmak için My kod budur

Bu uygulama ile ilgili sorun şu ki, dâhili bir tampon alan olduğu gibi belli bir seviyeye kadar dışarıda olsa bile, hala snackbar (latlng sınırları içinde) gösterir. Hala dili tespit ediyorum. Kesin olmasını istiyorum. Bunu nasıl düzeltebilirim?

cevap

1

Belirli bir konum yerine konum sınırları içerisinde olup olmadığını kontrol bir List<LatLng> tarafından temsil edilen çokgen içinde yatıyor olmadığını kontrol etmek Google Maps Android API Utility Library den PolyUtil.containsLocation yöntemi kullanabilirsiniz.

Örnek:

// Construct a List<LatLng> representing a Polygon 
List<LatLng> polygon = new ArrayList<>(); 
polygon.add(new LatLng(3,0)); 
polygon.add(new LatLng(3,3)); 
polygon.add(new LatLng(0,3)); 
polygon.add(new LatLng(3,0)); 

// Find the LatLngBounds of the Polygon 
LatLngBounds.Builder builder = new LatLngBounds.Builder(); 
for (LatLng point : polygon) { 
    builder.include(point); 
} 

LatLng test = new LatLng(1,1); 

boolean isInsideBoundary = builder.build().contains(test); // true as the test point is inside the boundary 
boolean isInside = PolyUtil.containsLocation(test, polygon, true); // false as the test point is outside the polygon 
+0

i alıyorum kütüphane dahil ederken hata: Hata: ': needToPark: processDebugResources' Yürütme görev için başarısız oldu. > Hata: 'com.google.maps.android' paket adıyla birden fazla kitaplık var Bu hatayı geçici olarak android.enforceUniquePackageName = false ile devre dışı bırakabilirsiniz Ancak, bu geçici ve 1.0 – Victor

+0

içinde uygulanacaktır Nasıl ekliyorsunuz kütüphane? Bunu kendi projenize eklemek için 'build.gradle'' 'bağımlılıkları' bölümüne' compile 'com.google.maps.android: android-map-utils: 0.4 +' 'ifadesini ekleyin. – antonio

+0

Yaptığım şey buydu. Hala aynı sorunu yaşıyoruz. Bu hatayı neden aldığımı anlamaya çalışıyorum. Build.gradle içinde compile 'com.google.maps.android:android-maps-utils:0.4+' eklendi – Victor