How to compute a radius around a point in an Android MapView?

I have a MapView that I'm displaying a "useful radius" (think accuracy of coordinate) in. Using MapView's Projection's metersToEquatorPixels, which is admittedly just for equatorial distance) isn't giving me an accurate enough distance (in pixels). How would you compute this if you wanted to display a circle around your coordinate, given radius?


Asked by: Brooke445 | Posted: 20-01-2022






Answer 1

So, Google Maps uses a Mercator projection. This means that the further you get from the equator the more distorted the distances become. According to this discussion, the proper way to convert for distances is something like:

public static int metersToRadius(float meters, MapView map, double latitude) {
    return (int) (map.getProjection().metersToEquatorPixels(meters) * (1/ Math.cos(Math.toRadians(latitude))));         
}

Answered by: Gianna848 | Posted: 21-02-2022



Answer 2

mMap.addCircle(
    new CircleOptions().center(
        new LatLng(
            bounds.getCenter().latitude, 
            bounds.getCenter().longitude
        )
    )
    .radius(50000)
    .strokeWidth(0f)
    .fillColor(0x550000FF)
);

Answered by: Haris608 | Posted: 21-02-2022



Answer 3

projection.toPixels(GeoP, pt);
float radius = projection.metersToEquatorPixels(50);

Try this and see... i used it on my MapRadius and it seems to be working

Answered by: Andrew119 | Posted: 21-02-2022



Similar questions

java - Android - Compute times a two numbers appear in cell number

Could anyone help me. I am trying to compute the number of times certain numbers appear in a table layout row - vertically and Horizontally, in other words. I would like to fill an array of numbers between say (4 and 5) to make it so that the number say 4 appears only 4times and 5 only twice (vertically & Horizontally) in say 6 * 6..take note How can I work with any of this? p...


android - How to compute app widget bitmap size?

I have a working widget that uses layouts and RemoteViews and scales itself nicely to whatever home screen area assigned to it. However, I need to display custom fonts and thus must re implement using an explicit bitmap and here is where the problems start, computing the bitmap size ended up to be a tough problem. What is a good formula to compute the widget bitmap size in pixels as a function of these values (and...


Android compute hash of a bitmap

I want to compute a SHA1 hash of different bitmaps (SHA isn't forced). The problem is that there are some bitmaps (captchas) wich are basicly the same, but the name changes often. I've found this: Compute SHA256 Hash in Android/Java and C# But it isn't the soloution i wanted. The Bitmap...


java - compute bounds in Path object returns 0

I have a simple drawing app for android and I would like to detect if a user has clicked on a line. To speed this process up I would like to get the bounds of all the Paths and check if the user input is within the bounds to quickly eliminate some of the paths. The problem I am encountering is that the method: pathInstance.computeBounds(boundsObject,false); Always returns 0, O...


java - Android: Faster way to compute hash

This code will compute the hash of a URI: protected void ShowHash(android.net.Uri uri) { MessageDigest md = null; try { md = MessageDigest.getInstance("MD5"); BufferedInputStream is = new BufferedInputStream(getContentResolver().openInputStream(uri)); DigestInputStream dis = new DigestInputStream(is, md); while(dis.read() != -1) ; Toast.makeText(getApplication...


Using compute shader in Android 5 (Open GL ES 3.1)

I am learning about OpenGL ES and in particular, compute shaders in OpenGL ES 3.1, specifically, in Android 5.0.1. I have 3 shaders defined (compute, vertex, and fragment) and attached to two different programs, one for the compute shader and one for the vertex and fragment shaders. I have no problem when I only use the vertex and fragment shaders but now that I added the compute shader I get the following...


Stuck with compute shader in Android 5.1.1 (Opengl 3.1)

I have written very simple program to get values from compute shader and render it directly on to the screen. I am suspecting that the shader storage buffer is not being binded to my vbo after I call all necessary compute shader methods. I am sharing the code please see if there are some errors. No compilation error I am getting and moreover the device I am using also supports gl 3.1 that I have checked.


java - Android Unable to compute hash error

I am having an issue when I run assembleRelease. This is the stack trace: * Exception is: org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:packageRelease'. at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActi...


android - Unable to compute hash

When I started to build against API 23 of Android, gradle plugin 1.3.1, gradle 2.7, I can't generate the APK any more. Maybe something with ProGuard but I don't understand what it is. I've looked at a lot of similar problems here at stackoverflow but can't find the solution. Error:Execution failed for task ':MyApp:packageDebug'. > Unable to compute hash of D:\Android\Projects\xxx\xxx\build\intermediates\...


java - Why NTP could not compute delay time

I'm using NTP from common-net library to synchronize time for my Android app. I'm try to get the delay using this code: public static final String TIME_SERVER = "time-a.nist.gov"; public static long getCurrentNetworkTime() throws IOException { NTPUDPClient timeClient = new NTPUDPClient(); InetAddress inetAddress = InetAddress.getByName(TIME_SERVER); TimeInfo timeInfo = timeClient.getTime(inetAd...






Still can't find your answer? Check out these communities...



Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android



top