Android向Google地方信息数据库添加地点不起作用 [英] Android Add Place to Google Places database doesn't work

查看:134
本文介绍了Android向Google地方信息数据库添加地点不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发使用Google地图和Google地方信息的Android应用程序。
当用户长时间点击地图时,我会向他展示他可以添加有关他点击地点的详细信息的表单,然后我想将其作为新Google地方添加到Google数据库中。
这是我在提交表单之前和之后所做的:

I'm developing an android application using Google Maps and Google Places. When a user makes a long click on the map, I show him a form in which he can add details about his clicked place, and then I want to add it to Google Database as a new Google Place. This is what I do when before and after he submits the form:

in onCreate():

mGoogleApiClient = new GoogleApiClient
                .Builder(this)
                .addApi(Places.GEO_DATA_API)
                .enableAutoManage(this, 0, this)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .build();

提交表单后:

private void addPlaceToGoogleDbAndToTrip()
{
    final Double lat = getIntent().getExtras().getDouble("lat");
    final Double lng = getIntent().getExtras().getDouble("lng");
    final String placeName = newPlaceNameET.getText().toString();
    final String address = newPlaceAddressET.getText().toString();
    final String website = newPlaceWebsiteET.getText().toString();
    final String phoneNumber = newPlacePhoneET.getText().toString();
    LatLng latlng = new LatLng(lat, lng);

AddPlaceRequest place =
        new AddPlaceRequest(
                placeName, // Name
                latlng, // Latitude and longitude
                address, // Address
                Collections.singletonList(Place.TYPE_POINT_OF_INTEREST), // Place types
                phoneNumber, // Phone number
                Uri.parse("www.SomeWebsite.co.il") // Website
        );

Places.GeoDataApi.addPlace(mGoogleApiClient, place).setResultCallback(new ResultCallback<PlaceBuffer>()
{
    @Override
    public void onResult(PlaceBuffer places)
    {

        if (!places.getStatus().isSuccess()) {

            Log.e(TAG, "Place query did not complete. Error: " + places.getStatus().toString());
            places.release();
            return;
        }

        final Place place = places.get(0);
        newPlaceID = place.getId();
        Log.i(TAG, "Place add result: " + place.getName());
        places.release();

    }
});
}

places.get(0)用于返回一个空的地方,现在我甚至没有得到那个......我得到一个返回结果的错误。它说:ERROR_OPERATION_FAILED,分辨率=空。

but places.get(0) used to return an empty place, and now I don't even get that... I get an Error on the result coming back back. it says: "ERROR_OPERATION_FAILED, resolution=null".

我的清单也有这个:

my manifest has this as well:

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

<meta-data
    android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />
<meta-data
    android:name="com.google.android.maps.v2.API_KEY"
    android:value="@string/google_maps_key" />

任何想法可能是什么问题?这些API在我的开发人员控制台中启用。

Any idea what might be the problem? The APIs are enabled in my developers console.

谢谢!

Thank you!

推荐答案

使用 com.google.android.geo.API_KEY 而不是 com.google.android.maps.v2.API_KEY

这篇关于Android向Google地方信息数据库添加地点不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆