From c0c1028dcf57379db68a87d8d0a1780d9d901fe5 Mon Sep 17 00:00:00 2001 From: Asheem Mamoowala Date: Wed, 10 May 2017 11:16:44 -0700 Subject: [core] Add toDouble Conversion method for correctly parsing Lat Lng coordinates --- include/mbgl/style/conversion.hpp | 1 + include/mbgl/style/conversion/coordinate.hpp | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'include') 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`, absence indicating `v` is not a JSON boolean * `toNumber(v)` -- returns `optional`, absence indicating `v` is not a JSON number + * `toDouble(v)` -- returns `optional`, absence indicating `v` is not a JSON number * `toString(v)` -- returns `optional`, absence indicating `v` is not a JSON string * `toValue(v)` -- returns `optional`, 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> { +struct Converter { public: template - optional> operator() (const V& value, Error& error) const { + optional 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 latitude = toNumber(arrayMember(value, 1)); - optional longitude = toNumber(arrayMember(value, 0)); + optional latitude = toDouble(arrayMember(value, 1)); + optional 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(*latitude, *longitude) }; + return LatLng(*latitude, *longitude); } }; -- cgit v1.2.1