public class Plcpickr extends AppCompatActivity {
int PLACE_PICKER_REQUEST = 1;
Button btn;
TextView t;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_plcpickr);
btn= (Button)findViewById(R.id.button2);
t = (TextView)findViewById(R.id.textView);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
PlacePicker.IntentBuilder builder = new
PlacePicker.IntentBuilder();
try {
startActivityForResult(builder.build(Plcpickr.this),
PLACE_PICKER_REQUEST);
} catch (GooglePlayServicesRepairableException |
GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent
data) {
if (requestCode == PLACE_PICKER_REQUEST) {
if (resultCode == RESULT_OK) {
Place place = PlacePicker.getPlace(data, this);
StringBuilder stBuilder = new StringBuilder();
String placename = String.format("%s", place.getName());
String latitude = String.valueOf(place.getLatLng().latitude);
String longitude = String.valueOf(place.getLatLng().longitude);
String address = String.format("%s", place.getAddress());
stBuilder.append("Name: ");
stBuilder.append(placename);
stBuilder.append("\n");
stBuilder.append("Latitude: ");
stBuilder.append(latitude);
stBuilder.append("\n");
stBuilder.append("Logitude: ");
stBuilder.append(longitude);
stBuilder.append("\n");
stBuilder.append("Address: ");
stBuilder.append(address);
t.setText(stBuilder.toString());
}
}
}
}
Logcat错误
/com.example.jimmy.placepicker I / dalvikvm:找不到方法android.content.pm.PackageManager.getPackageInstaller,从com.google.android.gms.common.zzo.zzy 11-09 12方法引用: 41:38.400 10227-10227 / com.example.jimmy.placepicker W / dalvikvm:VFY:无法解析虚方法492:Landroid / content / pm / PackageManager; .getPackageInstaller()Landroid / content / pm / PackageInstaller; 11-09 12:41:38.400 10227-10227 / com.example.jimmy.placepicker D / dalvikvm:VFY:替换操作码0x6e