Thursday, June 19, 2014

Android using intent based get MapDirection


Android using intent based get MapDirection :





Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
Uri.parse("http://maps.google.com/maps?saddr="+my_lat+","+my_long+"&daddr="+13.0820617+","+ 80.2755867));
startActivity(intent);

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();
}

}