Client given me a particular area map image. Here I need to get the longitude and latitude of the location at the Touch point on the image.
Is there any way I can work on this issue. To get the location of touch point on the image programmatically.
You can really only do this with any accuracy on a MapView, where you can use the methods
GeoPoint fromPixels(int x,
int y)
Create a new GeoPoint from pixel coordinates relative to the top-left
of the MapView that provided this PixelConverter.
and
toPixels
android.graphics.Point toPixels(GeoPoint in,
android.graphics.Point out)
Converts the given GeoPoint to onscreen pixel coordinates, relative to
the top-left of the MapView that provided this Projection.
to transform lat/on to screen coordinates.
If it's a plain old .png the, as long as the view covers a small area (a few square miles only), you could interpolate the lat/lon at the corners to get an approximate value for the touch point. If it was a whole country, then you would have to apply a coordinate transformation to map from a flat Mercator projection to a curved surface.
Related
On Google Map Api V2 for Android,
I would like to calculate the longest distance in kilometers displayed on screen (while zoom factor is a parameter) in order to determinate the radius of the smallest circle containing all the map displayed on screen at present time:
That means the distance between the center of the screen and one of the edges.
Is there some Tool I can use to do that ? (Maybe to get the coordinates of one of the edges...)
You can probably use the Projection class (http://developer.android.com/reference/com/google/android/gms/maps/Projection.html)
For example:
Projection projection = map.getProjection(); // get map projection
VisibleRegion vr = projection.getVisibleRegion(); //
vr now contains the corners of your map, from there you can compute the distances...
http://developer.android.com/reference/com/google/android/gms/maps/model/VisibleRegion.html
It would probably be wise to do this inside an OnCameraChangedListener , to be sure you have valid a projection value
How do I draw a area circle overlay underneath a marker?
For instance you would give the area circle an origin coordinate (Latitude, Longitude) and a radius relative to the origin.
So when you zoom in and out of the map the circle will scale with the zoom level correctly.
There is no standard Overlay in osmdroid for that, but it's quite easy to implement that by copying and simplifying this one: DirectedLocationOverlay
It's not easy explaining my problem but I will try.
I have an android GoogleMap, on top of it, I have an ImageView positioned at its center at all times. If I drag/pan the map, the pin will always be in the center of the GoogleMap.
Now, I add a marker, somewhere on the map. I want to zoom such that the center point remains in the center of the map, and the marker is visible within the map, and to the highest zoom level.
The problem is if I simply check if the marker is within boundaries of the map or not, and then keep zooming in/out till it is, this process will always repeat itself, i.e. trying to zoom in and if the marker became outside, then zoom out.
The problem is I rely on an OnCameraChange listener which will keep calling itself everytime I zoom in or out, hence, the process of zooming in/out will keep occuring indefinitely
journeyGoogleMap.setOnCameraChangeListener(new OnCameraChangeListener()
{
#Override
public void onCameraChange(final CameraPosition position)
{
Basically, what I need is a function where I can provide the center LatLng and the markerLatLng and it will automatically calculate the LatLngBounds making sure my center is within the center of the LatLng bounds, and then I can simply use
public static CameraUpdate newLatLngBounds (LatLngBounds bounds, int width, int height, int padding)
as shown in the link below
https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/CameraUpdateFactory#newLatLngBounds(com.google.android.gms.maps.model.LatLngBounds,int, int,int)
If you need anymore clarification please do tell me
You need to calculate LatLngBounds from two points:
Your marker position and
Place on the opposite side of your current center.
The second is calculated like this:
LatLng other = new LatLng(2 * center.latitude - position.latitude, 2 * center.longitude - position.longitude);
See LatLngBoundsUtils.fromCenterAndPositions for a general solution.
Use googleMap.getProjection().getVisibleRegion() to get all four corners of screen as LatLng values forming trapezium. Calculate where trapezium intersects with line drawn through center and your marker. Scale factor is (distance from center to marker / distance from center to intersection point). Now just scale trapezium with this scale factor relative to center. This is new visible regison.
You may also use getVisibleRegion().latLngBounds to simplify calculation, but note that some areas of returned rectangle are actually not visible.
I have a MapView centered at point P. The user can't change the MapView center, but he can choose a radius of a circle to be display around point P, and change it dynamically with the map being redrawn at each change to show the new circle.
The thing is, i want the map to zoom in or out as necessary, in order to display the entire circle at the viewable area. I've tried this:
Projection proj = m_Map.getProjection();
Point mapCenterPixles = new Point();
proj.toMapPixels(center, mapCenterPixles);
float radiusPixels = proj.metersToEquatorPixels(newRadius);
IGeoPoint topLeft = proj.fromPixels(mapCenterPixles.x - radiusPixels,
mapCenterPixles.y - radiusPixels);
IGeoPoint bottomRight = proj.fromPixels(mapCenterPixles.x
+ radiusPixels, mapCenterPixles.y + radiusPixels);
m_Map.getController().zoomToSpan(
topLeft.getLatitudeE6() - bottomRight.getLatitudeE6(),
topLeft.getLongitudeE6() - bottomRight.getLongitudeE6());
But it seems i'm missing something, as the values passed to zoomToSpan() cause no chnage, I'm kind of lost here, can someone please shed some light on how to zoom the map to span a bounding box of the circle given its radius in meters, and its center points?
Google Maps zoom levels are defined in powers of two, so MapController#zoomToSpan() also zooms by powers of two.
Ergo, if the span you compute above is already displayable within the current zoom level, it's likely nothing would actually change visually in the map until you need to go to the next larger or smaller zoom level.
This behavior is somewhat vaguely described in the documentation for MapController#zoomToSpan
In Android, if I have a circle's radius and center value, how could I measure the latitude and longitude of about 1 km periphery of that circle?
Horizontal = x-axis = Longitude
Vertical = y-axis = Latitude
Latitude and longitude are terms necessary to define a position on a sphere, where two angles are necessary. These terms have no relevance to a circle, which exists only in one plane.
This is not an easy problem to solve as the distance between each latitude and longitude varies depending upon where on the globe you are (I'm sure some maths boffin could do it, but it is beyond me). For instance at the north and south pole one degree longitude measures no distance at all, but at the equator one degree can be several kilometers. If however your search only relates to a small are of the globe, then a you can make a reasonable approximation by using 1km = x degrees where x is the correct value where you are.
Terms "circle", "radius" implies a 2D flat plane geometry whereas "latitude", "longitude" implies a geographical coordinates on a 3D ellipsoid.
Putting these problems asides, let's assume, in fact that your "circle" is a point on the surface of our Earth and, the "radius" is a distance from this point. This will correct your terms so they define a 3D problem.
If a projection is given. Then we can specify the "center" in planar geometry coordinates (X, Y). We can specify all points distance "R" in geometry coordinates as (X + R * cos(phi), Y + r * sin(phi)) then we can use the projection to convert the geometry coordinates from planar to geographic i.e. longitude, latitude. The problem is 1000s of projections exists and not all a valid across the entire Earth.
Alternatively, you can define your 3D ellipsoid in 3D space using (X, Y, Z) coordinates. Then the wording of your problem must change. The "circle" because a sphere whose point is on the surface of the ellipsoid and the "radius" is the radius of the sphere. To compute all points distance "R" from the sphere you will need to intersect the sphere with the ellipsoid using trigonometry. After you have done this, you can convert the resultant 3D coordinates back to longitude, latitude based on the definition of your ellipsoid.