MapSnippets logoMapSnippets logo

Fuzzy Location Circle with MapTiler SDK

MapTiler SDK

Display an approximate location as a fuzzy circle polygon layer instead of an exact point for privacy.

progress_activityLoading map...
maptilersdk.config.apiKey = 'YOUR_MAPTILER_KEY';
const map = new maptilersdk.Map({
  container: 'map',
  style: maptilersdk.MapStyle.STREETS,
  center: [2.3522, 48.8566],
  zoom: 13
});
function fuzzyCircle(center, radiusKm, points = 64) {
  const coords = [];
  for (let i = 0; i <= points; i++) {
    const angle = (i / points) * 2 * Math.PI;
    const dx = radiusKm / (111.32 * Math.cos(center[1] * Math.PI / 180));
    const dy = radiusKm / 110.574;
    coords.push([center[0] + dx * Math.cos(angle), center[1] + dy * Math.sin(angle)]);
  }
  return { type: 'Feature', geometry: { type: 'Polygon', coordinates: [coords] } };
}
map.on('load', () => {
  map.addSource('zone', { type: 'geojson', data: fuzzyCircle([2.3522, 48.8566], 0.5) });
  map.addLayer({ id: 'zone-fill', type: 'fill', source: 'zone',
    paint: { 'fill-color': '#9C27B0', 'fill-opacity': 0.2 } });
  map.addLayer({ id: 'zone-border', type: 'line', source: 'zone',
    paint: { 'line-color': '#9C27B0', 'line-width': 2, 'line-dasharray': [4, 2] } });
});

How it works

Instead of showing an exact marker, this example draws a translucent circle around an approximate location. The fuzzyCircle function generates a GeoJSON polygon by computing points along a circle of a given radius in kilometers.

The radius (0.5 km in this example) determines the privacy level. A larger radius hides the exact location more effectively.

The dashed border and low opacity signal to users that the location is approximate, not precise.

Key APIs

API Description Docs
map.addSource() Add computed GeoJSON polygon docs.maptiler.com/sdk-js/api/
fill layer Render the privacy zone docs.maptiler.com/sdk-js/api/
line-dasharray Dashed border for approximate feel docs.maptiler.com/sdk-js/api/

FAQ

Should I offset the center for true privacy?

Yes. For real privacy, add a random offset to the center coordinate (server-side). The circle alone does not hide the center point mathematically.

Can I use Turf.js instead of the manual function?

Yes. turf.circle(center, radius) produces the same result with proper geodesic math and is more accurate at high latitudes.

Common mistakes

  • Showing the exact coordinate alongside the fuzzy circle: this defeats the purpose of obfuscation
  • Using too small a radius: under 100m, the circle narrows the location to a few buildings
  • Computing the circle client-side with real coordinates: for true privacy, offset the center server-side before sending to the client
auto_awesome

Build maps using MapTiler SDK with AI

Generate code like this fuzzy location circle with maptiler sdk example using the MapTiler SDK skill in your IDE.