java - Place marker at latitude and longitude of centre of map -
had issue needed place marker @ exact centre of map screen , looked @ lot of questions , answers not wanted do. app allows user move map , once crosshairs in centre of map @ desired location, tap button , marker appears @ location.
map.getprojection().fromscreenlocation met needs did not have coordinates not implement solution.
so answer in same situation.
so soltuion use getcameraposition method follows. , fired button r.id.addmarker in xml.
findviewbyid(r.id.addmarker).setonclicklistener( new view.onclicklistener(){ @override public void onclick(view view) { if(mymap != null){ double mylat = mymap.getcameraposition().target.latitude; double mylng = mymap.getcameraposition().target.longitude; latlng markerpoint = new latlng(mylat, mylng); mymap.addmarker(new markeroptions().position(markerpoint)).settitle("next marker"); } } } );
hope helps in same predicament.
Comments
Post a Comment