在Android中使用pubnub无法正确跟踪位置

时间:2016-07-25 12:38:30

标签: android pubnub

我想在Google地图中使用pubnub位置跟踪器跟踪朋友位置。最初我创建了频道名称并与朋友分享我的位置。在共享 lat long 值时,该值是正确的,但在此之后,该位置未正确共享。相反,当前用户位置显示在地图上。我在下面发布了错误回复。

如何分享和查看朋友的位置?

public class PubNubManager {

    public final static String TAG = "PUBNUB";

    public static Pubnub startPubnub() {
        Log.d(TAG, "Initializing PubNub");
        return new Pubnub("pub-c-3cfa8420-9dc7-4d03-a6b8-7a003537ed66", "sub-c-7ed859ba-4ef9-11e6-bfbb-02ee2ddab7fe");
    }

    public static void subscribe(Pubnub mPubnub, String channelName, Callback subscribeCallback) {
        // Subscribe to channel
        try {
            mPubnub.subscribe(channelName, subscribeCallback);
            Log.d(TAG, "Subscribed to Channel");
        } catch (PubnubException e) {
            Log.e(TAG, e.toString());
        }
    }

    public static void broadcastLocation(Pubnub pubnub, String channelName, double latitude,
                                         double longitude, double altitude) {
        JSONObject message = new JSONObject();
        try {
            message.put("lat", latitude);
            message.put("lng", longitude);
            message.put("alt", altitude);
            Log.d(TAG, "Sending JSON Message: " + message.toString());
            pubnub.publish(channelName, message, publishCallback);
        } catch (JSONException e) {
            Log.e(TAG, e.toString());
        }

    }

    public static Callback publishCallback = new Callback() {

        @Override
        public void successCallback(String channel, Object response) {
            Log.d("PUBNUB", "Sent Message: " + response.toString());
        }

        @Override
        public void errorCallback(String channel, PubnubError error) {
            Log.d("PUBNUB", error.toString());
        }
    };
}

GMaps Share: Location Detected
07-25 17:57:22.460 12516-12516/io.atlanticlab.pubnubmaptracker D/PUBNUB: Sending JSON Message: {"alt":1,"lng":78.1256751,"lat":9.9504371}
07-25 17:57:22.620 12516-12788/io.atlanticlab.pubnubmaptracker D/PUBNUB: [Error: 129-0] : Page Not FoundPlease verify if network is reachable.Please contact support with error details. : []

`

0 个答案:

没有答案