Angular.js HTTP Concatenation - Changing URL - Breaks Angular

Hi,
I have a small problem with an Angular.js app.
I’m using a module (ngGeolocation) which fetches GeoIP data and provides the parts that I am interested in as $geolocation.position.coords.longitude & $geolocation.position.coords.latitude.
They works perfectly and display the latitude and longitude when called in angular expressions in the webpage (for testing purposes - {{ $geolocation.position.coords.longitude }} etc…)
However, I want to use the postcodes.io API to find a local postcode from this.
I can get the postcode from set latitude and longitude but, when I try to concatenate the real, current latitude and longitude it breaks angular.

This example with set latitude and longitude works:
$http.get(‘//api.postcodes.io/postcodes?limit=1&lon=-0.1276250&lat=51.5033630’)

This, however, does not:

$http.get(‘//api.postcodes.io/postcodes?limit=1&lon=’ + $geolocation.position.coords.longitude + ‘&lat=’ + $geolocation.position.coords.latitude);

I’m still pretty new to this so maybe I’m doing something stupid…
Thanks for reading

Hi,

That sounds a bit odd.
Could you please provide enough code to recreate your problem.

A Float precision problem?

As Pullo said, really need to see code for anything more than guesses.

In particular, the parts that deal with $geolocation.position.coords.___

Right before this line:

$http.get(‘//api.postcodes.io/postcodes?limit=1&lon=’ + $geolocation.position.coords.longitude + ‘&lat=’ + $geolocation.position.coords.latitude);

Place this.

console.log($geolocation.position.coords.longitude);
console.log($geolocation.position.coords.latitude);

In the console check what the value of that actually is.

To deal with these issues I recommend setting up real time JavaScript debugging. I use PHPStorm for it but I think you can do it with just the Chrome browser. The alternative is just using console.log as I showed which is much less efficient but works.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.