how to get the address of center point of GoogleMap v2 in android? -
i following this tutorial position of center point of v2 googlemap .now want address of point using reverse geocoding ....
i using following code latlang of center point when button clicked :
@override public void onclick(view view) { if(view.getid()==r.id.btn_set_location){ visibleregion visibleregion = map.getprojection() .getvisibleregion(); point x = map.getprojection().toscreenlocation( visibleregion.farright); point y = map.getprojection().toscreenlocation( visibleregion.nearleft); point centerpoint = new point(x.x / 2, y.y / 2); latlng centerfrompoint = map.getprojection().fromscreenlocation( centerpoint); } }
i have seen others tutotials address using latitude , longitude seperately in case have got latlang ,how address using latlang..need here ....if there others ways center point of map , address of same point ...any kind of appreciated ...thank
i think, want pass latlang parameters.i solved problem following code:
private class reversegeocoding extends asynctask<latlng, void, string> { context mcontext; public reversegeocoding(context context){ super(); mcontext = context; } // finding address using reverse geocoding @override protected string doinbackground(latlng... params) { geocoder geocoder = new geocoder(mcontext); double latitude = params[0].latitude; double longitude = params[0].longitude; list<address> addresses = null; string addresstext=""; try { addresses = geocoder.getfromlocation(latitude, longitude,1); } catch (ioexception e) { e.printstacktrace(); } if(addresses != null && addresses.size() > 0 ){ address address = addresses.get(0); addresstext = string.format("%s, %s, %s", address.getmaxaddresslineindex() > 0 ? address.getaddressline(0) : "", address.getlocality(), address.getcountryname()); } return addresstext; }
hope work ourt you>>>
after editing:
you can follow this , if working on activity class if working on fragment class following codes work you:
new reversegeocoding(getactivity()).execute(centerfrompoint);
Comments
Post a Comment