android地方选择器或谷歌地图api

时间:2016-03-09 16:59:49

标签: android google-maps google-maps-android-api-2

我希望看到所有附近的地方并使用地方选择器,但当我开始应用程序选择器出现并消失时,我无法理解为什么,请帮助,thx和对不起我的eng。 如果你有一些优惠我怎么能看到附近没有选择器的地方,请告诉我=)

UPD: 尝试更改com.google.android.geo.API_KEY上的com.google.android.maps.v2.API_KEY无法提供帮助。

MainActivity:

public class MainActivity extends AppCompatActivity {

private Button btPlacesAPI;
private TextView tvPlaceAPI;

private int PLACE_PICKER_REQUEST = 1;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    tvPlaceAPI = (TextView) findViewById(R.id.tv_place_id);

    btPlacesAPI = (Button)findViewById(R.id.bt_ppicker);
    btPlacesAPI.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
            try {

                startActivityForResult(builder.build(MainActivity.this), PLACE_PICKER_REQUEST);


            } catch (GooglePlayServicesRepairableException e) {
                e.printStackTrace();
            } catch (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(this,data);
            String toastMsg = String.format(
                    "Place: %s \n" +
                            "Alamat: %s \n" +
                            "Latlng %s \n", place.getName(), place.getAddress(), place.getLatLng().latitude+" "+place.getLatLng().longitude);
            tvPlaceAPI.setText(toastMsg);
        }
    }
}

}

清单:

<?xml version="1.0" encoding="utf-8"?>

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".ActivityMap"></activity>

    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="AIzaSyAej54bA3F_PnWkVYX1XfKoEevcfC5RtXM" />


</application>

1 个答案:

答案 0 :(得分:0)

<meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="Server_key" />

密钥应该是服务器密钥而不是android api密钥 请参阅此链接http://www.androidrey.com/google-places-api-for-android-place-picker/