@@ -150,6 +150,9 @@ window.app = {
150150 return ;
151151 }
152152 console . log ( "RESULT" , result ) ;
153+ if ( ! result ) {
154+ return ;
155+ }
153156 places . push (
154157 ...result
155158 . map ( ( place ) => {
@@ -185,31 +188,33 @@ window.app = {
185188 ) ;
186189 } ,
187190 calculateDistance ( address ) {
188- if ( window . app . state . location ) {
189- let origin = {
190- latitude : window . app . state . location . lat ,
191- longitude : window . app . state . location . lng ,
192- } ;
193-
194- let destination = {
195- latitude : address . lat ,
196- longitude : address . lng
197- } ;
198- let distance = buildfire . geo . calculateDistance ( origin , destination , {
199- decimalPlaces : 5 ,
200- } ) ;
201- let str = null ;
202- if ( distance < 0.5 ) {
203- str = Math . round ( distance * 5280 ) . toLocaleString ( ) + " ft" ;
204- }
205- else {
206- if ( window . app . state . distanceUnit ) {
207- str = Math . round ( distance * 1.60934 ) . toLocaleString ( ) + " km" ;
208- } else {
209- str = Math . round ( distance ) . toLocaleString ( ) + " mi" ;
191+ if ( address ) {
192+ if ( window . app . state . location ) {
193+ let origin = {
194+ latitude : window . app . state . location . lat ,
195+ longitude : window . app . state . location . lng ,
196+ } ;
197+
198+ let destination = {
199+ latitude : address . lat ,
200+ longitude : address . lng
201+ } ;
202+ let distance = buildfire . geo . calculateDistance ( origin , destination , {
203+ decimalPlaces : 5 ,
204+ } ) ;
205+ let str = null ;
206+ if ( distance < 0.5 ) {
207+ str = Math . round ( distance * 5280 ) . toLocaleString ( ) + " ft" ;
208+ }
209+ else {
210+ if ( window . app . state . distanceUnit ) {
211+ str = Math . round ( distance * 1.60934 ) . toLocaleString ( ) + " km" ;
212+ } else {
213+ str = Math . round ( distance ) . toLocaleString ( ) + " mi" ;
214+ }
210215 }
216+ return str ;
211217 }
212- return str ;
213218 }
214219 } ,
215220 init : ( placesCallback , positionCallback ) => {
@@ -265,6 +270,8 @@ window.app = {
265270 localStorage . setItem ( 'user_location' , JSON . stringify ( window . app . state . location ) )
266271 buildfire . spinner . hide ( ) ;
267272 getPlacesList ( )
273+ } else {
274+ buildfire . spinner . hide ( ) ;
268275 }
269276 } ) ;
270277 }
0 commit comments