2

I'm new to web development. I am writing a javascript webapp and am unclear on the syntax to access GeoFirestore's calculateDistance utility function and get the error ReferenceError: calculateDistance is not defined. This function is located in the utils.ts TypeScript file, but somehow I'm not picking it up.

I've tried various syntaxes to call the "calculateDistance" function as well as trying various paths.

I thought pulling the full geofirestore.js library would be sufficient to pull in the utils functions.

Utils.ts documentation is here.

My index.html file snippet:

<script src="https://unpkg.com/geofirestore/dist/geofirestore.js"></script>

My Javascript module snippet:

let geopoint1 = new firebase.firestore.GeoPoint(40.123, -120.456)
let geopoint2 = new firebase.firestore.GeoPoint(-20.456, 100.123)
console.log("Distance: " + calculateDistance(geopoint1,geopoint2).toString() + " km")

I get the following error. "ReferenceError: calculateDistance is not defined"

YEG
  • 473
  • 4
  • 12

2 Answers2

0

The calculateDistance function is not exported outside of the library (aka it's not made for you to use). However as the maintainer of geofirestore I'd recommend you trying out my library geokit which provides a distance calculation method => https://github.com/MichaelSolati/geokit#geokitdistancestart-latlngliteral-end-latlngliteral-unit-string-number

MichaelSolati
  • 2,847
  • 1
  • 17
  • 29
-1

Your syntax for using the ‘calculateDistance’ function is correct. The only error here is that your Javascript cannot find the ‘calculateDistance’ function. Try downloading the geofirestore project here and running your code locally. Your error could also be occurring because of where you are putting your tags. This link will be helpful figuring out where to put your tags for external libraries.