android - How to get villagename, district and subdistrict from latitude longitude -
i have latitude , longitude co-ordinate , want village name district , sub district that. searched , found reverse geocode not give village name. there api or codebase getting exact location lat long. want show in android app.
geocoder geocoder = new geocoder(this, locale.getdefault()); string result = null; try { list<address> addresslist = geocoder.getfromlocation( 25.882456,83.174279, 1); if (addresslist != null && addresslist.size() > 0) { address address = addresslist.get(0); stringbuilder sb = new stringbuilder(); (int = 0; < address.getmaxaddresslineindex(); i++) { sb.append(address.getaddressline(i)).append("\n");//adress } sb.append(address.getlocality()).append("\n");//village sb.append(address.getpostalcode()).append("\n"); sb.append(address.getcountryname()); sb.append(address.getadminarea()).append("\n"); //state sb.append(address.getsubadminarea()).append("\n");//district result = sb.tostring(); } } catch (ioexception e) { // log.e(tag, "unable connect geocoder", e); }
i changed in ur code , working
import java.io.ioexception; import java.util.list; import java.util.locale; import android.app.alertdialog; import android.content.context; import android.location.address; import android.location.geocoder; import android.os.bundle; import android.support.v4.app.fragmentactivity; import android.util.log; import android.widget.toast; import com.google.android.gms.maps.googlemap; import com.google.android.gms.maps.supportmapfragment; import com.google.android.gms.maps.model.bitmapdescriptorfactory; import com.google.android.gms.maps.model.latlng; import com.google.android.gms.maps.model.marker; import com.google.android.gms.maps.model.markeroptions; public class mainactivity extends fragmentactivity { private googlemap mmap; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); setupmapifneeded(); } @override protected void onresume() { super.onresume(); setupmapifneeded(); } private void setupmapifneeded() { if (mmap != null) { return; } mmap = ((supportmapfragment) getsupportfragmentmanager().findfragmentbyid(r.id.map)).getmap(); if (mmap == null) { return; } // initialize map options. example: // mmap.setmaptype(googlemap.map_type_hybrid); final latlng india = new latlng(28.5192, 77.2130); // string address=getaddress(this, 28.5192, 77.2130); marker melbourne = mmap.addmarker(new markeroptions() .position(india) .title("saket") .snippet("population: 4,137,400")); // string address=getaddress(this,28.6700, 77.4200); geocoder geocoder = new geocoder(this, locale.getdefault()); string result = null; try { list<address> addresslist = geocoder.getfromlocation( 25.882456,83.174279, 1); if (addresslist != null && addresslist.size() > 0) { address address = addresslist.get(0); stringbuilder sb = new stringbuilder(); (int = 0; < address.getmaxaddresslineindex(); i++) { sb.append(address.getaddressline(i)).append("\n");//adress } sb.append(address.getlocality()).append("\n");//village sb.append(address.getpostalcode()).append("\n"); sb.append(address.getcountryname()); sb.append(address.getadminarea()).append("\n"); //state sb.append(address.getsubadminarea()).append("\n");//district sb.append(address.getsublocality()).append("\n"); result = sb.tostring(); } } catch (ioexception e) { // log.e(tag, "unable connect geocoder", e); } new alertdialog.builder(this).setmessage(result).create().show(); toast.maketext(getapplicationcontext(), result, toast.length_long).show(); final latlng ghaziabad = new latlng(24.1860076, 75.1432231); marker ghaziabad = mmap.addmarker(new markeroptions() .position(ghaziabad) .title(result) .snippet("population: 4,137,400") .icon(bitmapdescriptorfactory.fromresource(r.drawable.ic_launcher))); }
Comments
Post a Comment