지오 코더를 사용하여 주어진 좌표의 사용자 위치를 인쇄하려고하는 활동을하고 있지만 getFromLocation을 호출 할 때마다 충돌합니다. 나는지도 열쇠를 어디에도 두지 않았다. 이것이 프로그램이 충돌하는 주된 이유인지 여부를 알고 싶습니다. 여러 버전의 에뮬레이터를 시도했지만 어디서나 같은 기능으로 충돌합니다. 열쇠가 필요한 경우 어디에서 그것을 넣을까요 ?? INTERNET nd ACCESS_FINE_LOCATION 이외의 다른 권한이 필요합니다. 코드는 다음과 같습니다.Geocoder가 Android 에뮬레이터에서 작동하도록지도 API가 필요합니까?
package com.mapsgps.test;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
//import com.mapsgps.test.googleGod;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.location.Address;
import android.location.Criteria;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class startAct extends Activity implements OnClickListener, LocationListener{
Button stopButton;
Geocoder geocoder;
Double latitude = 0.0;
Double longitude = 0.0;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
stopButton = (Button) findViewById(R.id.stop);
stopButton.setOnClickListener(this);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
LocationListener ll = new startAct();
Log.d("Hello", "I have been started");
/*String provider = lm.getBestProvider(criteria, true);
Location location = lm.getLastKnownLocation(provider);
Log.d("Hello", "I have been given something");
latitude = location.getLatitude();
longitude = location.getLongitude();
String lat = latitude + "";
String lgt = longitude + "";
Log.d("LOCATION CHANGED", lat);
Log.d("LOCATION CHANGED", lgt);
*/
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll);
geocoder = new Geocoder(this, Locale.ENGLISH);
Log.d("Hello", "I have been created location");
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Log.d("Clicked", "here clicked");
}
public void onLocationChanged(Location location) {
Log.d("Listening", "Changed");
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
String lat = latitude + "";
String lgt = longitude + "";
Log.d("LOCATION CHANGED", lat);
Log.d("LOCATION CHANGED", lgt);
}
else{
Log.d("Null", "Location is null");
}
String place = "City";
int maxResult = 5;
String addressList[] = new String[maxResult];
Log.d("Before Context", "testing");
maxResult = maxResult + 2;
Log.d("Before Context", "testing2");
try {
Log.d("Trying", "testing");
List<Address> addresses = geocoder.getFromLocation(latitude, longitude, maxResult);
Log.d("Trying", "got location");
if(addresses != null) {
Log.d("Trying", "I am not null");
for (int j = 0; j < maxResult; j++){
Address returnedAddress = addresses.get(j);
StringBuilder strReturnedAddress = new StringBuilder();
for(int i = 0; i < returnedAddress.getMaxAddressLineIndex(); i++) {
strReturnedAddress.append(returnedAddress.getAddressLine(i)).append("\n");
}
Log.d("Finshed", "Hard work done");
addressList[j] = strReturnedAddress.toString();
Log.v("Addr", addressList[j]);
}
}
else{
}
} catch (IOException e) {
// TODO Auto-generated catch block
Log.d("IO exception", "I cupped");
}
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
그것은 휴가의 몇 주 : 당신은 API 키를 지정하는 방법을 알고 싶다면
, 그것은 다음과 같이 보입니다. 그러면 ACCESS_FINE_LOCATION이됩니다. –