安卓程序无法获取位置信息的问题

康德的吉他 康德的吉他 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
写了个安卓程序来获取网页位置信息:
MainActivity.java:
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();

}

});




}
}

后面带有“/////////////”的语句是调试用的。运行程序点按下按钮输出到Log.d("yinan", "#############");/////////结束,说明没有执行
HttpResponse httpResponse = httpClient.execute(new HttpGet(url));语句,为什么,求帮助~~~!
...全文

相关推荐

评论 5
收藏 已收藏
分享
返回顶部
康德的吉他
Android 80,489 成员 91,375 内容