Issue with Google Maps toScreenLocation() method Android -


as title mentions, i'm having issues toscreenlocation() google maps.

i'm trying pick arbitrary points on google maps broadcasting google maps fragment. within fragment, want screen point latlng coordinate corresponds with. however, of time error following:

caused by: java.lang.illegalargumentexception: left == right         @ android.opengl.matrix.frustumm(matrix.java:327)         @ com.google.maps.api.android.lib6.gmm6.o.b.b.j(unknown source)         @ com.google.maps.api.android.lib6.gmm6.o.b.b.l(unknown source)         @ com.google.maps.api.android.lib6.gmm6.o.b.b.a(unknown source)         @ com.google.maps.api.android.lib6.gmm6.o.b.b.c(unknown source)         @ com.google.maps.api.android.lib6.gmm6.c.y.a(unknown source)         @ com.google.maps.api.android.lib6.c.az.a(unknown source)         @ com.google.android.gms.maps.internal.ca.ontransact(sourcefile:74)         @ android.os.binder.transact(binder.java:380)         @ com.google.android.gms.maps.internal.iprojectiondelegate$zza$zza.toscreenlocation(unknown source)         @ com.google.android.gms.maps.projection.toscreenlocation(unknown source)         @ com.example.tracker.googlemaps.googlemapstracker.convertcoordinates(googlemapstracker.java:163)         @ com.example.tracker.googlemaps.googlemapstracker.access$100(googlemapstracker.java:38)         @ com.example.tracker.googlemaps.googlemapstracker$2.onreceive(googlemapstracker.java:153)         @     android.app.loadedapk$receiverdispatcher$args.run(loadedapk.java:866) 

the code corresponds conversion is:

    private void convertcoordinates(float latitude, float longitude){     location = new latlng(latitude, longitude);     if(location.latitude != (float) 0.0 || location.longitude != (float) 0.0){         //point map = mapview.getmap().getprojection().toscreenlocation(location);          point map = projection.toscreenlocation(location);         screenadjustments.setlati(map.y);         screenadjustments.setlongi(map.x);     } else {         log.e(tag, "bad coordinates!!!");     } } 

i have verified getting in float values , hard coded them be. of time when hits point map = projection.toscreenlocation(location); throw error frustum.

i need in figuring out how work.

i first tried code , got no error.

according here, tired toscreenlocation , works. remember set ongloballayoutlistener make sure map view , waiting layout process settle.

sample code:

public class mainactivity extends fragmentactivity {      googlemap mgooglemap;     private static latlng mountainview = new latlng(37.42, -122.08);     private static latlng mountainview2 = new latlng(37.421, -122.081);     view mapview;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);           // initial map         try {              if (mgooglemap == null) {                 mgooglemap = ((supportmapfragment) getsupportfragmentmanager().findfragmentbyid(r.id.map)).getmap();             }         } catch (exception e) {             e.printstacktrace();         }          mapview = getsupportfragmentmanager().findfragmentbyid(r.id.map).getview();          mgooglemap.getuisettings().setmylocationbuttonenabled(true);         mgooglemap.getuisettings().setzoomcontrolsenabled(true);         mgooglemap.getuisettings().setzoomgesturesenabled(true);          //mgooglemap.animatecamera(cameraupdatefactory.newlatlngzoom(mountainview, 15));          marker marker = mgooglemap.addmarker(new markeroptions()                 .position(mountainview)                 .title("have nice day!"));          convertcoordinates((float) 37.42, (float) -122.08);      }      private void convertcoordinates(float latitude, float longitude) {         final latlng location = new latlng(latitude, longitude);         if (location.latitude != (float) 0.0 || location.longitude != (float) 0.0) {             if (mapview.getviewtreeobserver().isalive()) {                 mapview.getviewtreeobserver().addongloballayoutlistener(new viewtreeobserver.ongloballayoutlistener() {                     @override                     public void ongloballayout() {                         // remove listener                         // ! before jelly bean:                         mapview.getviewtreeobserver().removeglobalonlayoutlistener(this);                         // ! jelly bean , later:                         //mapview.getviewtreeobserver().removeongloballayoutlistener(this);                         // set map viewport                         // center latlng object center of map                         mgooglemap.movecamera(cameraupdatefactory.newlatlngzoom(location, 15));                         // ! can query projection object here                         point markerscreenposition = mgooglemap.getprojection().toscreenlocation(location);                         // ! example output in test code: (356, 483)                         log.d("x!!!!", markerscreenposition.x + "");                         log.d("y!!!!", markerscreenposition.y + "");                     }                 });              } else {                 //log.e(tag, "bad coordinates!!!");             }         }     } } 

it works , output x = 639, y = 1049 on nexus 6.


Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -