optimize location query