Usage: map.Zoom = CalculateGMapZoom(mapa. Return (zoom > maxZoomLevel ? (double)maxZoomLevel: (zoom < minZoomLevel ? (double)minZoomLevel: (double)zoom)) Int pixels = mapSize.Width >= mapSize.Height ? mapSize.Height : mapSize.Width //get the shortest dimmension of the mapĭouble k = (double)pixels * 156543.03392 * Math.Cos(latitude * Math.PI / 180) ![]() Static double CalculateGMapZoom(Size mapSize, int coverage, double latitude, double distance, int minZoomLevel, int maxZoomLevel) / Distance to show from this point in meters / Latitude where the point to draw is located / The size of the control (map size in pixels) / Zoom map to fit the desired distance from point Use this function in order to get the best zoom based on your current location and a distance to the point (C# code tested with on VS2022 but zoom levels and algorithm are the same for Google): /// Meters_per_pixel = 156543.03392 * s(latLng.lat() * Math.PI / 180) / Math.pow(2, zoom)įormula is from Chris Broadfoot's comment. A formula for calculating the correct scale based on latitude is: Google Maps uses a Mercator projection so the scale varies substantially with latitude. It appears that the extra zoom level available for Static Maps is just an upsampled version of the max-resolution image from the Javascript API. Note that these values are for the Google Static Maps API which seems to give one more zoom level than the Javascript API.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |