'Map Is Zooming (Zoom In/Out) Automatically when i changed Latitude and Longitude To View different location (Please Go through the below Description)

I am using Gmap nuget package to load the map in my project. i have loaded the map, after that i want to draw the circle around the selected Lat Long. i drawn the circles and those circles are in correct distance also (i have verified). The issue is : as i am changing latitude and longitude to to view another location map, the map is zooming automatically. As latitude number is increases the map is zooming in and as latitude number decreases zooming out is taking place. I am not using any zoom in/out function only changing latitude is acting like this

Eg : Bangalore Latitude:13.095170176351234 and longitude : 77.59453327374854

For above lat long assume its in Default Zoom.

Now I am going Switch the lat long to Dhelhi Location to View Dhelhi Map Latitude : 28.55635085552201 and Longitude : 77.09994706900083

while loading Dhelhi Map we can see the Map Zoom In taking place**

absorve Circle Width,Height and Map while loading To Dhelhi location we can see the Zoom In because latitude number is bigger than bangalore Latitude number

 private static double localLatitude = 13.095170176351234;
 private static double localLongitude = 77.59453327374854;    

private void mapView_Loaded(object sender, RoutedEventArgs e)
{
    GMaps.Instance.Mode = AccessMode.ServerAndCache;
    mapView.MapProvider=GMap.NET.MapProviders.OpenStreetMapProvider.Instance;
    mapView.MinZoom = 12;
    mapView.MaxZoom = 17;
    mapView.Zoom = 14;
    mapView.MouseWheelZoomType = MouseWheelZoomType.ViewCenter;
    mapView.CanDragMap = false;
    mapView.DragButton = MouseButton.Left;
    mapView.Position = new PointLatLng(localLatitude, localLongitude);
    mapView.IsHitTestVisible = true;
    mapView.ShowCenter = true;
    CreateCircle(localLatitude, localLongitude, 30, 0.4, 4);
    CreateCircle(localLatitude, localLongitude, 500, 0.4);
    CreateCircle(localLatitude, localLongitude, 1000, 0.4);
    CreateCircle(localLatitude, localLongitude, 1500, 0.4);
    CreateCircle(localLatitude, localLongitude, 2000, 0.4);
    CreateCircle(localLatitude, localLongitude, 2150, 0.4);
}


private void CreateCircle(double rLat, double rLon, double rangeRadius, double opacity, double ColorIndex = 1)
        {

            //double radius = 2150; // in mtr //todo get from erc
            double radius = rangeRadius;
            //int ColorIndex = 1;

            PointLatLng point = new PointLatLng(rLat, rLon);

            //GMapMarker markers = new GMapMarker(point);
            int segments = 1080;

            List<PointLatLng> pointillist = new List<PointLatLng>();

            for (int i = 0; i < segments; i++)
            {
                pointillist.Add(FindPointAtDistanceFrom(point, i * (Math.PI / 180), radius / 1000));
            }
            var rangeCircles = new GMapPolygon(pointillist)
            {
                Tag = "RangeCircle"
            };
            mapView.RegenerateShape(rangeCircles);
            switch (ColorIndex)
            {
                case 1:
                    ((Path)rangeCircles.Shape).Fill = Brushes.LightGray;
                    break;
                case 2:
                    ((Path)rangeCircles.Shape).Fill = Brushes.Orange;
                    break;
                case 3:
                    ((Path)rangeCircles.Shape).Fill = Brushes.Aqua;
                    break;
                case 4:
                    ((Path)rangeCircles.Shape).Fill = Brushes.Red;
                    break;
                default:
                    System.Windows.MessageBox.Show("No search zone found!");
                    break;
            }
            ((Path)rangeCircles.Shape).Stroke = Brushes.Black;
            ((Path)rangeCircles.Shape).StrokeThickness = 1;
            ((Path)rangeCircles.Shape).Opacity = opacity;
            mapView.Markers.Add(rangeCircles);      
        }

private static GMap.NET.PointLatLng FindPointAtDistanceFrom(GMap.NET.PointLatLng startPoint, double initialBearingRadians, double distanceKilometres)
{
     const double radiusEarthKilometres = 6371.01;
     var distRatio = distanceKilometres / radiusEarthKilometres;
     var distRatioSine = Math.Sin(distRatio);
     var distRatioCosine = Math.Cos(distRatio);

     var startLatRad = DegreesToRadians(startPoint.Lat);
     var startLonRad = DegreesToRadians(startPoint.Lng);

     var startLatCos = Math.Cos(startLatRad);
     var startLatSin = Math.Sin(startLatRad);

     var endLatRads = Math.Asin((startLatSin * distRatioCosine) + (startLatCos * distRatioSine * Math.Cos(initialBearingRadians)));
     var endLonRads = startLonRad + Math.Atan2(Math.Sin(initialBearingRadians) * distRatioSine * startLatCos, distRatioCosine - startLatSin * Math.Sin(endLatRads));

     return new GMap.NET.PointLatLng(RadiansToDegrees(endLatRads), RadiansToDegrees(endLonRads));
}

 private static double DegreesToRadians(double degrees)
{
  const double degToRadFactor = Math.PI / 180;
  return degrees * degToRadFactor;
}
private static double RadiansToDegrees(double radians)
{
  const double radToDegFactor = 180 / Math.PI;
  return radians * radToDegFactor;

}



Solution 1:[1]

It might be the mapView.ShowCenter = true; property that is causing the automatic zoom adjustments. Requiring the center point to always be visible probably causes your map to zoom to try to show both the new marker and the center in the same visible map window.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 devangela