Thursday, June 19, 2014
android using latlong based get zipcode
Latlong based get zipcode
======================
new asynctask_zipcode(Activity name.this).execute();
public class asynctask_zipcode extends AsyncTask<Void, Integer, Void> {
public asynctask_zipcode(Activity activity) {
context = activity;
}
private Context context;
@Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
XPath xpath = XPathFactory.newInstance().newXPath();
String expression = "//GeocodeResponse/result/address_component[type=\"postal_code\"]/long_name/text()";
InputSource inputSource = new InputSource("https://maps.googleapis.com/maps/api/geocode/xml?latlng="+"latStr" +","+ "longStr" +"&sensor=true");
try {
zipcode = (String) xpath.evaluate(expression, inputSource, XPathConstants.STRING);
} catch (XPathExpressionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
Toast.makeText(context, zipcode, 1000).show();
}
}
======================
new asynctask_zipcode(Activity name.this).execute();
public class asynctask_zipcode extends AsyncTask<Void, Integer, Void> {
public asynctask_zipcode(Activity activity) {
context = activity;
}
private Context context;
@Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
XPath xpath = XPathFactory.newInstance().newXPath();
String expression = "//GeocodeResponse/result/address_component[type=\"postal_code\"]/long_name/text()";
InputSource inputSource = new InputSource("https://maps.googleapis.com/maps/api/geocode/xml?latlng="+"latStr" +","+ "longStr" +"&sensor=true");
try {
zipcode = (String) xpath.evaluate(expression, inputSource, XPathConstants.STRING);
} catch (XPathExpressionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
Toast.makeText(context, zipcode, 1000).show();
}
}
Subscribe to:
Comments (Atom)
