pubnub / eon-map

Realtime maps with PubNub and MapBox.
https://www.pubnub.com/developers/eon/
MIT License
135 stars 51 forks source link

Cannot get my own pubnub key working on eon-map #2

Closed xianlin closed 9 years ago

xianlin commented 9 years ago

I cannot get it working by using the below script, the requetsed url is still "demo" url

http://ps4.pubnub.com/subscribe/demo/my-map/0/0?uuid=some_long_string&pnsdk=PubNub-JS-Web%2F3.7.8


<script>

  var channel = 'my-map';

  eon.map({
    id: 'map',
    mb_token: 'pk.ey31IjoiaWRtc3giLCJhIjoiZZ1zMGI2ZjBlNTMxZjk5YTEwNjM5WNJlOWI4MmJiZGIifQ.U1jMQo2QVeuUtt85oD7hkQ',
    mb_id: 'mapbox.streets',
    subscribe_key: 'my_own_pubnub_sub_key',
    channel: channel
  });

</script>

However if I used the below script, it works

<script>
var output = PUBNUB.$('output')
,   pubnub = PUBNUB.init({ subscribe_key : 'my_own_key' });

pubnub.subscribe({
    channel  : 'my-map',
    callback : function(message) {
        output.innerHTML = [
            JSON.stringify(message), '<br>', output.innerHTML
        ].join('');
    }
});
</script>

The only differences is I am not using eon-map eon.map function.

Could someone please show how to use own pubnub key

stephenlb commented 9 years ago

Using your own PubNub API Keys with Eon Maps

You can set the pubnub init parameter when using Eon Maps. This allows you to configure PubNub client connections with extra security options such a auth_key and your cipher_key. You should also set secure: true and ssl: true as well.

<div id="map"></div>
<script>
  var pubnub  = PUBNUB({ subscribe_key : 'my_own_key', ssl : true });
  var channel = 'my-map';
  eon.map({
    pubnub   : pubnub,  // < - - - here < - - - //
    channel  : channel,
    id       : 'map',
    mb_id    : 'mapbox.streets',
    mb_token : 'pk.ey31IjoiaWRtc3giLCJhIjoiZZ1zMGI2ZjBlNTMxZjk5YTEwNjM5WNJlOWI4MmJiZGIifQ.U1jMQo2QVeuUtt85oD7hkQ'
  });
</script>

I added the docs here: https://github.com/pubnub/eon-map/blob/master/README.md#configure-using-your-own-pubnub-api-keys

ianjennings commented 9 years ago

Hey @xianlin,

Sorry, the documentation was outdated. The method you (and @stephenlb) describe is correct.

Ian

stephenlb commented 9 years ago

:+1: 👍:+1: 👍

xianlin commented 9 years ago

bus

Thank you guys, finally got it working... will try other services Pubnub offers...

stephenlb commented 9 years ago

Very nice!