i developing android google map application, showing current location on map starting.
i have search bar in application, when user enter area name, second marker placed on location.
now problem is, how second marker longitude , latitude position , make route between 2 markers.
my mainactivity.java code follows:
public class mainactivity extends fragmentactivity implements onmapreadycallback { private googlemap mmap; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_maps); // obtain supportmapfragment , notified when map ready used. supportmapfragment mapfragment = (supportmapfragment) getsupportfragmentmanager() .findfragmentbyid(r.id.map); mapfragment.getmapasync(this); } public void onmapsearch(view view) { edittext locationsearch = (edittext) findviewbyid(r.id.edittext); string location = locationsearch.gettext().tostring(); list<address> addresslist = null; if (location != null || !location.equals("")) { geocoder geocoder = new geocoder(this); try { addresslist = geocoder.getfromlocationname(location, 1); } catch (ioexception e) { e.printstacktrace(); } address address = addresslist.get(0); latlng latlng = new latlng(address.getlatitude(), address.getlongitude()); mmap.addmarker(new markeroptions().position(latlng).title("marker")); mmap.animatecamera(cameraupdatefactory.newlatlng(latlng)); } } @override public void onmapready(googlemap googlemap) { mmap = googlemap; // add marker in sydney , move camera latlng sydney = new latlng(27.746974, 85.301582); mmap.addmarker(new markeroptions().position(sydney).title("kathmandu, nepal")); mmap.movecamera(cameraupdatefactory.newlatlng(sydney)); if (activitycompat.checkselfpermission(this, manifest.permission.access_fine_location) != packagemanager.permission_granted && activitycompat.checkselfpermission(this, manifest.permission.access_coarse_location) != packagemanager.permission_granted) { return; } // enable mylocation button in map mmap.setmylocationenabled(true); } }
please me.
in program have used code latlng of second marker.
latlng latlng = new latlng(address.getlatitude(), address.getlongitude()); mmap.addmarker(new markeroptions().position(latlng).title("marker"));
to make polyline, refer link. question has been answered.
https://www.simplifiedcoding.net/google-maps-distance-calculator-google-maps-api/
Comments
Post a Comment