You can use the debug sidebar window to help you to know how to extract the required data.
First thing is to feed your data into a debug node and trigger the flow.
I did this using the attached flow. By the way, in this forum you need to surround code with 3 backticks in order to allow one to extract the code (or JSON data) for analysis.
[{"id":"5f94bdd.434a644","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"e4f9b076.c2873","type":"inject","z":"5f94bdd.434a644","name":"","topic":"","payload":"{\"topic\":\"device_tracker.hans_gpslogger\",\"payload\":\"home\",\"data\":{\"entity_id\":\"device_tracker.hans_gpslogger\",\"old_state\":{\"entity_id\":\"device_tracker.hans_gpslogger\",\"state\":\"home\",\"attributes\":{\"source_type\":\"gps\",\"latitude\":-23.962159,\"longitude\":135.0735714,\"gps_accuracy\":22,\"battery\":35,\"speed\":0,\"direction\":0,\"altitude\":52.400001525878906,\"provider\":\"network\",\"activity\":\"\",\"friendly_name\":\"hans gpslogger\"},\"last_changed\":\"2018-06-24T12:15:31.055553+00:00\",\"last_updated\":\"2018-06-24T12:29:57.684507+00:00\"},\"new_state\":{\"entity_id\":\"device_tracker.hans_gpslogger\",\"state\":\"home\",\"attributes\":{\"source_type\":\"gps\",\"latitude\":-23.962159,\"longitude\":135.0735714,\"gps_accuracy\":22,\"battery\":35,\"speed\":0,\"direction\":0,\"altitude\":52.400001525878906,\"provider\":\"network\",\"activity\":\"\",\"friendly_name\":\"hans gpslogger\"},\"last_changed\":\"2018-06-24T12:15:31.055553+00:00\",\"last_updated\":\"2018-06-24T12:31:00.039979+00:00\"}},\"_msgid\":\"b5ee0937.997978\"}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":174.10000610351562,"y":178,"wires":[["ff9590a9.83b88"]]},{"id":"ff9590a9.83b88","type":"debug","z":"5f94bdd.434a644","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":352.100004196167,"y":176.00000190734863,"wires":[]},{"id":"14602b01.647bb5","type":"inject","z":"5f94bdd.434a644","name":"","topic":"","payload":"{\"topic\":\"device_tracker.hans_gpslogger\",\"payload\":\"home\",\"data\":{\"entity_id\":\"device_tracker.hans_gpslogger\",\"old_state\":{\"entity_id\":\"device_tracker.hans_gpslogger\",\"state\":\"home\",\"attributes\":{\"source_type\":\"gps\",\"latitude\":-23.962159,\"longitude\":135.0735714,\"gps_accuracy\":22,\"battery\":35,\"speed\":0,\"direction\":0,\"altitude\":52.400001525878906,\"provider\":\"network\",\"activity\":\"\",\"friendly_name\":\"hans gpslogger\"},\"last_changed\":\"2018-06-24T12:15:31.055553+00:00\",\"last_updated\":\"2018-06-24T12:29:57.684507+00:00\"},\"new_state\":{\"entity_id\":\"device_tracker.hans_gpslogger\",\"state\":\"home\",\"attributes\":{\"source_type\":\"gps\",\"latitude\":-23.962159,\"longitude\":135.0735714,\"gps_accuracy\":22,\"battery\":35,\"speed\":0,\"direction\":0,\"altitude\":52.400001525878906,\"provider\":\"network\",\"activity\":\"\",\"friendly_name\":\"hans gpslogger\"},\"last_changed\":\"2018-06-24T12:15:31.055553+00:00\",\"last_updated\":\"2018-06-24T12:31:00.039979+00:00\"}},\"_msgid\":\"b5ee0937.997978\"}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":168,"y":280,"wires":[["987d1958.0e0978"]]},{"id":"987d1958.0e0978","type":"change","z":"5f94bdd.434a644","name":"","rules":[{"t":"set","p":"oldlatitude","pt":"msg","to":"payload.data.old_state.attributes.latitude","tot":"msg"},{"t":"set","p":"oldlongitude","pt":"msg","to":"payload.data.old_state.attributes.longitude","tot":"msg"},{"t":"set","p":"newlatitude","pt":"msg","to":"payload.data.new_state.attributes.latitude","tot":"msg"},{"t":"set","p":"newlongitude","pt":"msg","to":"payload.data.new_state.attributes.longitude","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":326.1000061035156,"y":280,"wires":[["7730e280.b8b43c"]]},{"id":"7730e280.b8b43c","type":"debug","z":"5f94bdd.434a644","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":539,"y":282,"wires":[]}]
We can see the result in the debug side panel. The small icon >_ that appears when you hover your mouse in the lines of the debug indicates that you have latitude and longitude in four different places in the JSON structure:
payload.data.old_state.attributes.latitude
payload.data.old_state.attributes.longitude
payload.data.new_state.attributes.latitude
payload.data.new_state.attributes.longitude
You can use above paths to extract the data into the msg object, like I did in the flow attached above. Actually there is no need to write code for this, just using a change node will do the trick.
