This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var pubnub = new PubNub({ | |
| publishKey: 'YOUR_KEYS_HERE', | |
| subscribeKey: 'YOUR_KEYS_HERE' | |
| }); | |
| var xhr = new XMLHttpRequest(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "timestamp": "2016-08-23T22:31:40.255Z", | |
| "Novato": { | |
| "geo": "38.1074° N, 122.5697° W", | |
| "temperature": { | |
| "F": "99.9", | |
| "C": "37.7" | |
| }, | |
| "humidity": "40.965", | |
| "barometric": "1011.8", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class FlightPathsTabContentFragment extends Fragment implements OnMapReadyCallback { | |
| ... | |
| private static ImmutableMap<String, String> getNewLocationMessage(String userName, int randomLat, int randomLng, long elapsedTime) { | |
| String newLat = Double.toString(generatorOriginLat + ((randomLat + elapsedTime) * 0.000003)); | |
| String newLng = Double.toString(generatorOriginLng + ((randomLng + elapsedTime) * 0.00001)); | |
| return ImmutableMap.<String, String>of("who", userName, "lat", newLat, "lng", newLng); | |
| } | |
| ... | |
| private void scheduleRandomUpdates() { | |
| this.executorService = Executors.newSingleThreadScheduledExecutor(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class FlightPathsMapAdapter { | |
| ... | |
| private List<LatLng> polylinePoints; | |
| ... | |
| public void locationUpdated(final Map<String, String> newLocation) { | |
| if (newLocation.containsKey("lat") && newLocation.containsKey("lng")) { | |
| String lat = newLocation.get("lat"); | |
| String lng = newLocation.get("lng"); | |
| doUiUpdate(new LatLng(Double.parseDouble(lat), Double.parseDouble(lng))); | |
| } else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class FlightPathsPnCallback extends SubscribeCallback { | |
| ... | |
| @Override | |
| public void message(PubNub pubnub, PNMessageResult message) { | |
| if (!message.getChannel().equals(watchChannel)) { | |
| return; | |
| } | |
| try { | |
| Log.d(TAG, "message: " + message.toString()); | |
| Map<String, String> newLocation = JsonUtil.fromJson(message.getMessage().toString(), LinkedHashMap.class); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ... | |
| @Override | |
| public void onMapReady(GoogleMap map) { | |
| this.map = map; | |
| pubNub.addListener(new FlightPathsPnCallback(new FlightPathsMapAdapter((Activity) this.getContext(), map), Constants.FLIGHTPATHS_CHANNEL_NAME)); | |
| pubNub.subscribe().channels(Arrays.asList(Constants.FLIGHTPATHS_CHANNEL_NAME)).execute(); | |
| scheduleRandomUpdates(); | |
| } | |
| ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class FlightPathsTabContentFragment extends Fragment implements OnMapReadyCallback { | |
| ... | |
| @Override | |
| public View onCreateView(LayoutInflater inflater, ViewGroup container, | |
| Bundle savedInstanceState) { | |
| View view = inflater.inflate(R.layout.fragment_flightpaths, container, false); | |
| SupportMapFragment mapFragment = (SupportMapFragment) getChildFragmentManager() | |
| .findFragmentById(R.id.map_flightpaths); | |
| mapFragment.getMapAsync(this); | |
| return view; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class LocationHelper implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, LocationListener { | |
| ... | |
| public LocationHelper(Context context, LocationListener mLocationListener) { | |
| this.mGoogleApiClient = new GoogleApiClient.Builder(context) | |
| .addConnectionCallbacks(this) | |
| .addOnConnectionFailedListener(this) | |
| .addApi(LocationServices.API) | |
| .build(); | |
| this.mGoogleApiClient.connect(); | |
| this.mLocationListener = mLocationListener; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class LocationPublishMapAdapter { | |
| ... | |
| public void locationUpdated(final Map<String, String> newLocation) { | |
| if (newLocation.containsKey("lat") && newLocation.containsKey("lng")) { | |
| String lat = newLocation.get("lat"); | |
| String lng = newLocation.get("lng"); | |
| doUiUpdate(new LatLng(Double.parseDouble(lat), Double.parseDouble(lng))); | |
| } else { | |
| Log.w(TAG, "message ignored: " + newLocation.toString()); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class LocationPublishPnCallback extends SubscribeCallback { | |
| ... | |
| @Override | |
| public void message(PubNub pubnub, PNMessageResult message) { | |
| if (!message.getChannel().equals(watchChannel)) { | |
| return; | |
| } | |
| try { | |
| Log.d(TAG, "message: " + message.toString()); | |
| Map<String, String> newLocation = JsonUtil.fromJson(message.getMessage().toString(), LinkedHashMap.class); |