【发布时间】:2013-12-29 09:40:41
【问题描述】:
我希望程序能够使用 Location location.getLatitude()/Location location.getLongitude 方法返回上述 a 和 b 值的值,但每当我用返回双精度值的方法替换 a 和 b 时getLongitude 和 getLatitude 提供的值或实际的 get 函数本身,我得到一个错误。
public void onClick(View v) {
requesturl = "https://maps.googleapis.com/maps/api/place/search/json?" +
"location=" + a + "," + b + "&radius=6000&" + "types=bank&sensor=false&key=AIzaSyDXNlHRDZnWW0T0tvBUjpyA8k2K9sjS2cM";
HHand(requesturl);
}
我怎样才能让 a 和 b 可以从 getLatitude() 和 getLongitude() 函数中获取它们的值?
已编辑:代码
public class Freedom extends ActivityGroup implements LocationListener {
/** Called when the activity is first created.
* @return */
String keystring="";
String requesturl;
LocationManager locman;
Location location;
//Awesome
public String convertStreamToString(InputStream is) {
return new Scanner(is).useDelimiter("\\A").next();
}
public void HHand(String a) {
//HTTP Request Processing for URL
HttpClient client=new DefaultHttpClient();
StringBuilder builder=new StringBuilder(a);
builder.append(URLEncoder.encode(keystring));
HttpPost post=new HttpPost(a);
try {
org.apache.http.HttpResponse response=client.execute(post);
HttpEntity entity=response.getEntity();
if (entity != null) {
InputStream is = entity.getContent();
String val = convertStreamToString(is);
Log.e("", val);
}
}
catch (ClientProtocolException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
locman = (LocationManager) this.getSystemService(LOCATION_SERVICE);
}
protected void onResume() {
super.onResume();
locman.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 10, this);
}
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.btmmnu, menu);
return true;
}
protected Dialog onCreateDialog(int id) {
final Dialog dialog = new Dialog(this);
OnClickListener txtlstn = new OnClickListener() {
public void onClick(View v) {
dismissDialog(0);
}
};
switch(id) {
case 0:
...
}
return dialog;
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.About:
showDialog(0);
return true;
case R.id.Guidance:
final Button Travel = (Button) findViewById(R.id.travel);
Travel.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
requesturl = "https://maps.googleapis.com/maps/api/place/search/json?" +
"location=" + location.getLatitude() + "," + location.getLongitude() + "&radius=6000&" +
"types=car_rental&sensor=false&key=AIzaSyDXNlHRDZnWW0T0tvBUjpyA8k2K9sjS2cM";
HHand(requesturl);
}
});
【问题讨论】:
标签: java android google-maps