If you hit this error while working with Syncfusion Maps and Google Maps implementation, the problem is usually not the map data itself. It roots from the UrlTemplate; I suspect when the value is built using a zoom factor (double type) or any calculation that can produce Infinity or NaN.
Error: ”.NET number values such as positive and negative infinity cannot be written as valid JSON.”
Hypothesis
JSON does not allow Infinity, -Infinity, or NaN as numeric values. When Syncfusion serializes the map configuration, any invalid numeric result in a bound property can cause the JSON writer to fail. I suspect this often happens when a UrlTemplate is assembled from a zoom value, scale factor, or division that can sometimes evaluate to zero or an invalid result.
For example, if your template or helper method does something like:
var zoom = GetZoomFactor();
var url = $"https://example.com/maps/{100 / zoom}";
and zoom becomes 0, the result will be invalid and the serializer will throw this error.
What to check
First thing, let’s confirm this is what we’re dealing with; Replace the URL Template from the google tiles one to openstreet one (below).
https://a.tile.openstreetmap.org/level/tileX/tileY.png
If the error goes away, we’re on the right track.
Start by inspecting any code that generates the map URL or computes values used by the map component. Pay special attention to:
UrlTemplatevalues.- Zoom factor calculations.
- Division operations.
- Any computed
doubleordecimalvalues passed into the component. - Values that might come from JavaScript interop or external APIs.
If you are using Google Maps inside the template, the issue is often caused by the zoom value being manipulated incorrectly before it is inserted into the URL.
Probable fixes
- round off Map Zoom Factor/Level.
- use int types for Zoom Factor/Level, Min Zoom and Max Zoom.
I’ve got a few other bugs around this guy; when I’m certain, I’ll update this post.