【问题标题】:Geo-fensing and accuracy of google maps to locate particular place using paid version of google maps API谷歌地图的地理围栏和准确性,以使用付费版谷歌地图 API 定位特定地点
【发布时间】:2019-02-04 09:04:57
【问题描述】:

我正在尝试开发一个 android 应用程序,我想从 google maps API 获取以下详细信息。

  1. 是否可以使用付费版本的谷歌地图 API 为特定地点设置地理围栏(矩形或圆形)?如果是,那么我可以从谷歌地图 API 获得的准确度是多少(特定地点的米或英尺实习生)。

  2. 我能否使用 google maps API 读取用户在特定地点停留的时间?

  3. 当用户在特定地点停留一段时间(如第 2 点所述)时,android 操作系统是否可以在该手机中通知我的应用程序?

对于以上三个功能,我是否必须选择付费版的谷歌地图 API?或者也可以使用免费版的谷歌地图 API 来完成?

【问题讨论】:

    标签: android google-maps google-maps-api-3 google-maps-markers


    【解决方案1】:

    对于所有三个问题,答案都是肯定的。 第一个,你可以在Geofence的Builder中确定你想要得到的精度,像这样

    new Geofence.Builder()
                .setRequestId(key)
                .setCircularRegion(lat, lang, 150)
                .setExpirationDuration(Geofence.NEVER_EXPIRE)
                .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER)
                .setLoiteringDelay(1000)
                .build();
    

    我将精度设置为 150m(您应该知道的一件事是,您设置的精度越高,使用的功率就越多)

    对于第二个和第三个,您可以将TransitionTypes 设置为Geofence.GEOFENCE_TRANSITION_DWELL 以了解用户是否在一个地方停留一段时间。同时,您可以使用 PendingIntent 在此条件匹配时发送广播。完整代码如下

    Geofence geofence = getGeofence(lat, lng, key);
        geofencingClient.addGeofences(
                getGeofencingRequest(geofence),
                getGeofencePendingIntent(title, location, id))
                .addOnCompleteListener(task -> {
                    if (task.isSuccessful()) {
    
                    }else{
    
                    }
                });
    

    getGeofencingRequest的代码

    private GeofencingRequest getGeofencingRequest(Geofence geofence) {
        GeofencingRequest.Builder builder = new GeofencingRequest.Builder();
        builder.setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER);
        builder.addGeofence(geofence);
        return builder.build();
    }
    

    getGeofencePendingIntent的代码

    private PendingIntent getGeofencePendingIntent(String title, String location, long id) {
        Intent i = new Intent("add your unique ID for the broadcast");
        Bundle bundle = new Bundle();
        bundle.putLong(Reminder.ID, id);
        bundle.putString(Reminder.LOCATION_NAME, location);
        bundle.putString(Reminder.TITLE, title);
        i.putExtras(bundle);
        return PendingIntent.getBroadcast(
                getContext(),
                (int) id,
                i,
                0
        );
    }
    

    【讨论】:

    • 1.你的回答对我有帮助。我可以从谷歌地图 API 获得的以米为单位的最小精度是多少?我从手机上看到的是5米半径。我可以在矩形区域中设置地理围栏吗?就像你在代码“setCircularRegion”中给出的那样。
    • 最低准确度可以看this,我不认为gofence可以设置在矩形区域
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-13
    • 2014-02-20
    • 1970-01-01
    • 2014-06-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多