diff options
author | Asheem Mamoowala <asheem.mamoowala@mapbox.com> | 2017-05-10 11:16:44 -0700 |
---|---|---|
committer | Asheem Mamoowala <asheem.mamoowala@mapbox.com> | 2017-06-01 15:38:01 -0700 |
commit | c0c1028dcf57379db68a87d8d0a1780d9d901fe5 (patch) | |
tree | 0f3ee78d092dd8f010f6fe26554480a35b9b35f0 /include | |
parent | 7a010df9560e8807b9be938bb5ff7360e8e730a6 (diff) | |
download | qtlocation-mapboxgl-c0c1028dcf57379db68a87d8d0a1780d9d901fe5.tar.gz |
[core] Add toDouble Conversion method for correctly parsing Lat Lng coordinates
Diffstat (limited to 'include')
-rw-r--r-- | include/mbgl/style/conversion.hpp | 1 | ||||
-rw-r--r-- | include/mbgl/style/conversion/coordinate.hpp | 10 |
2 files changed, 6 insertions, 5 deletions
diff --git a/include/mbgl/style/conversion.hpp b/include/mbgl/style/conversion.hpp index d6fb3a6dd0..27504a89b1 100644 --- a/include/mbgl/style/conversion.hpp +++ b/include/mbgl/style/conversion.hpp @@ -46,6 +46,7 @@ namespace conversion { * `toBool(v)` -- returns `optional<bool>`, absence indicating `v` is not a JSON boolean * `toNumber(v)` -- returns `optional<float>`, absence indicating `v` is not a JSON number + * `toDouble(v)` -- returns `optional<double>`, absence indicating `v` is not a JSON number * `toString(v)` -- returns `optional<std::string>`, absence indicating `v` is not a JSON string * `toValue(v)` -- returns `optional<mbgl::Value>`, a variant type, for generic conversion, absence indicating `v` is not a boolean, number, or string. Numbers should be converted to diff --git a/include/mbgl/style/conversion/coordinate.hpp b/include/mbgl/style/conversion/coordinate.hpp index 0adbb9a7ee..736f5e94a2 100644 --- a/include/mbgl/style/conversion/coordinate.hpp +++ b/include/mbgl/style/conversion/coordinate.hpp @@ -8,17 +8,17 @@ namespace style { namespace conversion { template<> -struct Converter<std::unique_ptr<LatLng>> { +struct Converter<LatLng> { public: template <class V> - optional<std::unique_ptr<LatLng>> operator() (const V& value, Error& error) const { + optional<LatLng> operator() (const V& value, Error& error) const { if (!isArray(value) || arrayLength(value) < 2 ) { error = { "coordinate array must contain numeric longtitude and latitude values" }; return {}; } //Style spec uses GeoJSON convention for specifying coordinates - optional<float> latitude = toNumber(arrayMember(value, 1)); - optional<float> longitude = toNumber(arrayMember(value, 0)); + optional<double> latitude = toDouble(arrayMember(value, 1)); + optional<double> longitude = toDouble(arrayMember(value, 0)); if (!latitude || !longitude) { error = { "coordinate array must contain numeric longtitude and latitude values" }; @@ -28,7 +28,7 @@ public: error = { "coordinate latitude must be between -90 and 90" }; return {}; } - return { std::make_unique<LatLng>(*latitude, *longitude) }; + return LatLng(*latitude, *longitude); } }; |