java - Google Maps API markers dissapear -
package com.example.sander.app; import android.app.fragment; /** * created sander on 4-4-2017. */ import android.app.fragment; import android.content.pm.packagemanager; import android.location.address; import android.location.geocoder; import android.os.bundle; import android.support.annotation.nullable; import android.support.v4.app.activitycompat; import android.support.v4.content.contextcompat; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.manifest; import com.android.volley.request; import com.android.volley.requestqueue; import com.android.volley.response; import com.android.volley.volleyerror; import com.android.volley.toolbox.stringrequest; import com.android.volley.toolbox.volley; import com.google.android.gms.maps.cameraupdatefactory; import com.google.android.gms.maps.googlemap; import com.google.android.gms.maps.mapfragment; import com.google.android.gms.maps.mapview; import com.google.android.gms.maps.mapsinitializer; import com.google.android.gms.maps.onmapreadycallback; import com.google.android.gms.maps.model.bitmapdescriptorfactory; import com.google.android.gms.maps.model.latlng; import com.google.android.gms.maps.model.markeroptions; import org.json.jsonarray; import org.json.jsonexception; import org.json.jsonobject; import java.util.arraylist; import java.util.list; import java.util.locale; public class googlemaps extends fragment implements onmapreadycallback { list<string> list = new arraylist<>(); list<double> latitude = new arraylist<>(); list<double> longitude = new arraylist<>(); integer mlatitude = 0; integer mlongitude = 0; integer names = 0; @nullable @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { requestqueue rq = volley.newrequestqueue(getactivity().getapplicationcontext()); string url= "http://test.dontstealmywag.ga/api/parkgarage.php"; stringrequest stringrequest = new stringrequest(request.method.get, url, new response.listener<string>() { @override public void onresponse(string response) { // response try{ jsonobject o = new jsonobject(response); jsonarray values=o.getjsonarray("parkgarage"); ( int i=0; i< values.length(); i++) { jsonobject sonuc = values.getjsonobject(i); list.add("name: " + sonuc.getstring("parkgarage_name") + "\n"); longitude.add(sonuc.getdouble("langitude")); latitude.add(sonuc.getdouble("longitude")); } } catch (jsonexception ex){} } }, new response.errorlistener() { @override public void onerrorresponse(volleyerror error) { // handle error } }); rq.add(stringrequest ); return inflater.inflate(r.layout.fragment_gmaps, container, false); } @override public void onviewcreated(view view, bundle savedinstancestate) { super.onviewcreated(view, savedinstancestate); mapview mapview = (mapview) view.findviewbyid(r.id.map); mapview.oncreate(savedinstancestate); mapview.onresume(); // needed map display try { mapsinitializer.initialize(getactivity().getapplicationcontext()); } catch (exception e) { e.printstacktrace(); } mapview.getmapasync(this); } integer = 0; @override public void onmapready(googlemap googlemap) { latlng marker = new latlng(51.9244201, 4.4777325); for(i = 0; < list.size(); i++){ googlemap.addmarker(new markeroptions().title(list.get(i)).position(new latlng(longitude.get(i), latitude.get(i)))); } googlemap.movecamera(cameraupdatefactory.newlatlngzoom(marker, 12)); //googlemap.addmarker(new markeroptions().title(list.get(1)).position(marker)); if (activitycompat.checkselfpermission(getactivity(), manifest.permission.access_fine_location) != packagemanager.permission_granted && activitycompat.checkselfpermission(getactivity(), manifest.permission.access_coarse_location) != packagemanager.permission_granted) { // todo: consider calling // activitycompat#requestpermissions // here request missing permissions, , overriding // public void onrequestpermissionsresult(int requestcode, string[] permissions, // int[] grantresults) // handle case user grants permission. see documentation // activitycompat#requestpermissions more details. return; } googlemap.setmylocationenabled(true); googlemap.getuisettings().setcompassenabled(true); googlemap.getuisettings().setmylocationbuttonenabled(true); } }
i'm building app adds markers on map. getting name, lat & long json. maps inside fragment. @ start when click "maps" add markers, second time when click on "maps" markers disapear. me fix issue?
Comments
Post a Comment