#!/bin/bash
####################################################################
# Prey Geo Module - by Tomas Pollak (bootlog.org)
# URL: http://preyproject.com
# License: GPLv3
####################################################################

log ' -- Trying to get list of nearby Wifi access points...'
get_wifi_access_points

if [ -n "$wifi_points" ]; then

	log " -- Got it! Now lets try to get a location fix..."
	get_current_location
	parse_location_response

	local any_chars_in_lat=$(echo $current_lat | sed 's/[^a-z]//g')

	if [ -z "$any_chars_in_lat" ]; then

		add_trace 'lat' $current_lat
		add_trace 'lng' $current_lng
		add_trace 'accuracy' $spot_accuracy
		# add_trace 'address' "$current_address"
		# add_trace 'full' "$current_location_json"

	elif [ -n "$current_location_json" ]; then
    
		notify_exception "Bad Geolocation Response" "$current_location_json"
		log " !! Invalid response from geocoder service. Skipping geolocation data."
    
	else

		notify_exception "No Geolocation Response"
		log " !! Couldn't get a response from geocoder service. Skipping geolocation data."

	fi

else
	log " !! Couldn't get any Wifi information. Does this computer have Wifi capabilities?"
fi
