Possible Duplicate:
how to get the name entered by the user and search that respective location in edittext
I have actually written a code for showing google maps as per user in android. The user enters location in edit text which i have used in JSON for fetching latitude and longitude and have pointed the map to that latitude and longitude. Now the problem i am facing is i have stored the location dat user enters in a variable named location and i have passed dat variable in JSON. But whenever i run the program and enter whatso ever location, map is being pointed near Hyderabad.
I have implemented this code in a tabview
Here is my code...
the basic prob here is the latitude and longitude from json are not being passed to other page...
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.mapview);
Et = (EditText) findViewById(R.id.edt);
Bt = (Button) findViewById(R.id.Search);
location = Et.getText().toString();
final String readTwitterFeed = readTwi("http://maps.googleapis.com/maps/api/geocode/json?address=+location+&sensor=false");
Bt.setOnClickListener(new OnClickListener()
{
String strUrl,lon;
public void onClick(View v)
{
try
{
JSONObject jsonObject =new JSONObject(readTwitterFeed).getJSONArray("results").getJSONObject(0).getJSONObject("geometry").getJSONObject("location");
strUrl=jsonObject.getString("lat");
lon=jsonObject.getString("lng");
Log.i("location",strUrl);
Log.i("longtin",lon);
}
catch (Exception e)
{
e.printStackTrace();
}
Intent intent=new Intent(MapView.this,MapsActivity.class);
intent.putExtra("lat",strUrl);
intent.putExtra("lng",lon);
startActivity(intent);
}
});
}
private String readTwi(String url)
{
StringBuilder builder = new StringBuilder();
HttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
try {
HttpResponse response = client.execute(httpGet);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == 200) {
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(content));
String line;
while ((line = reader.readLine()) != null) {
builder.append(line);
}
} else {
Log.e(MapView.class.toString(), "Failed to download file");
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return builder.toString();
}