javascript - Working with accents in angularjs -
i have list of city names. if user picks 1 i'd set center of angular-google-map's city.
console.log works fine correct city name if pass function it's replacing accents.
$scope.selectcity = function (city) { console.log(city.name) //it works fine. log: abaújkér locationservice.getlatlngbycityname(city.name).then(function (result){ var citylatlng = result.data.results[0].geometry.location; console.log(citylatlng); }).catch(function (error) { console.log(error); }); };
locationservice.getlatlngbycityname returns bad request:
get http://maps.googleapis.com/maps/api/geocode/json?address=aba%fajk%e9r&sensor=true 400 (bad request)
the factory:
factory.getlatlngbycityname = function (city) { console.log(city); // works fine. log: abaújkér var api_url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' + city; return $http({ method: 'get', url: api_url, params: { sensor: true } }) .catch(function () { return $q.reject(); }); }
i guess encoding. how fix googleapis' url?
you need url encode parameters "special chars", use function:
Comments
Post a Comment