0
const url='https://api.mapbox.com/geocoding/v5/mapbox.places/Los%20Angeles.json?access_token=pk.eyJ1Ijoic2FtLWhhd2t6IiwiYSI6ImNrMDl2YXU4aTBieTEzY252aHpvZHd5Y3YifQ.v8Xh5bZiNbkTR7FlQwIgYQ'                                                     request=({url:url, json:true}, (error,response) =>{
const latitude = response.body.features[0].center[0]
const longitude = response.body.features[0].center[1]
console.log(latitude,longitude) })

Here I used an api to geocode my location but I'm getting a TypeError: Assigment to const variable. According to me that error should only come when the const value is changing in the code but it's staying the same throughout then where is the problem?

4
  • You are missing an = in the first line after url Commented Sep 7, 2019 at 18:37
  • @MohammedAmirAnsari that must've been misplaced during copying the code but it is there and I'm still getting the error. Commented Sep 7, 2019 at 18:39
  • Could you update the code and make sure it's correct, please. Commented Sep 7, 2019 at 18:42
  • @Hamza was doing that only :) Commented Sep 7, 2019 at 18:44

1 Answer 1

2

You had an extra = sign in your code, try this:

const url = 'https://api.mapbox.com/geocoding/v5/mapbox.places/Los%20Angeles.json?access_token=pk.eyJ1Ijoic2FtLWhhd2t6IiwiYSI6ImNrMDl2YXU4aTBieTEzY252aHpvZHd5Y3YifQ.v8Xh5bZiNbkTR7FlQwIgYQ';

request({ url: url, json: true }, (error, response) => {
  const latitude = response.body.features[0].center[0];
  const longitude = response.body.features[0].center[1];
  console.log(latitude,longitude);
})
Sign up to request clarification or add additional context in comments.

2 Comments

Got it. Thanks a lot!
So, why does the question not show a problem with this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.