Your "lat" and "lng" variable are not declared nor instantiated.
This is the way to set them:
var lat = marker.getPosition().lat();
var lng = marker.getPosition().lng();
reference: https://developers.google.com/maps/documentation/javascript/reference#LatLng