80,351
社区成员
发帖
与我相关
我的任务
分享
package com.example.location03;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
//import android.content.DialogInterface;
//import android.content.DialogInterface.OnClickListener;
public class MainActivity extends Activity {
private Button geocoding = null;
private Button reverseGeocoding = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
geocoding = (Button)findViewById(R.id.geocoding);
geocoding.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
new Thread(){
public void run(){
Log.d("yinan", "run");/////////
String url = "http://maps.google.com/maps/api/geocode/json?address=SFO&sensor=false";
String responseData = "" ;
Log.d("yinan", "url");/////////
HttpClient httpClient = new DefaultHttpClient();
Log.d("yinan", "DefaultHttpClient");/////////
try {
Log.d("yinan", "#############");/////////
HttpResponse httpResponse = httpClient.execute(new HttpGet(url));
Log.d("yinan", "httpResponse");/////////
HttpEntity entity = httpResponse.getEntity();
Log.d("yinan", "Entity!!!");/////////
BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent()));
String str;
Log.d("yinan", "OnClickListener");/////////
while((str = br.readLine()) != null){
Log.d("yinan", str);
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}.start();
}
});
}
}