Google Maps coordinates to perspective map image c

2019-09-20 00:02发布

问题:

I'm creating an android app that uses a image as a map.

I have a image in perspective and need to put some pins and show the user where he is.

How can I convert the google maps coordinates to the position in the image?

Thank you

回答1:

there is no code to share here since it it dependent on how you show the image (I assume you are not using GoogleMap object and ground overlay...

You have to create your specific function for reprojecting the image coordinates (that you can try to normalize between 0 and 1) and the world coordinates (which depends on where in the world is that place).

If you are using instead GoogleMap object, you can place that image over google maps and then use the normal coordinates; here the page: https://developers.google.com/maps/documentation/android/groundoverlay

you can add it by:

LatLng NEWARK = new LatLng(40.714086, -74.228697);
GroundOverlayOptions newarkMap = new GroundOverlayOptions()
        .image(BitmapDescriptorFactory.fromResource(R.drawable.newark_nj_1922))
        .position(NEWARK, 8600f, 6500f);
map.addGroundOverlay(newarkMap);

Obviously you have to find your position and check the documentation on which method use, because you can use the above one or a few others:

position(LatLng location, float width, float height)
position(LatLng location, float width)
positionFromBounds(LatLngBounds bounds)

PS: If you are not using GoogleMap objects this question is not "google-maps" related but GIS-geopositioning related (I would suggest https://gis.stackexchange.com/ in this case).