Unity mapbox - coordinates at center of zoomable map? - unity3d

I know how to move the zoomable map to a specific lat/long, and that point will be centered in the screen. If the user moves the map (drags it sideways), how do I get the coordinates at the point of the map that is now centered?
Thanks!

I would recommend to use the Camera.ScreenToWorldPoint method from Unity:
https://docs.unity3d.com/ScriptReference/Camera.ScreenToWorldPoint.html?_ga=2.95757022.39200391.1587116665-1246420375.1587116665
Please also have a look at this similar thread:
https://forum.unity.com/threads/how-to-get-a-world-position-from-the-center-of-the-screen.524573/

Thanks!
Based on the similar thread you pointed me to, I added a function to my QuadTreeCameraMovement...
public Vector2d GeoCoordsAtCenter() {
var centerScreen = _referenceCamera.ViewportToScreenPoint(new Vector3(.5f, .5f, _referenceCamera.transform.localPosition.y));
var pos = _referenceCamera.ScreenToWorldPoint(centerScreen);
var latlongDelta = _mapManager.WorldToGeoPosition(pos);
Debug.Log("CENTER: Latitude: " + latlongDelta.x + " Longitude: " + latlongDelta.y);
return latlongDelta;
}

Related

Get map center point on scrolling Google maps flutter

I'm doing an app in my app. I'm using google maps flutter and I'm having an issue regarding scrolling. When I scroll the map I want to get the center points (long, lat) of the map that is if I scroll the map and stop at certain place it would grab the location points of center.
Can anyone suggest how to solve this issue? It can be very helpful Thank you in advance..
I would get the bounds of the screen, and then find the center of those bounds. If you have a GoogleMapController for the GoogleMap, just use a function like this:
getCenter() async {
LatLngBounds bounds = await mapsController.getVisibleRegion();
LatLng center = LatLng(
(bounds.northeast.latitude + bounds.southwest.latitude) / 2,
(bounds.northeast.longitude + bounds.southwest.longitude) / 2,
);
return center;
}
In the latest version of google maps flutter we can get the coordinates of location by passing in the screen coordinatinates,
// some code here
Size screen = MediaQuery.of(context).size;
// some code here
final coords = await mapController.getLatLng(ScreenCoordinate( x: screen.width/2, y:
screen.width/2));

Bing Maps V8 SDK - Get drawn shapes

I have a Bing map with drawing manager enabled for users to draw shapes (mostly one polygon at a time). I want to be able to get the details of the drawn polygon so I can save it in the database.
The below function can access the shapes but returns the coordinates only
function getShapes()
{
var shapes = drawingManager.getPrimitives();
if (shapes && shapes.length > 0)
{
var rings = shapes[0].getRings();
alert('Retrieved ' + rings[0] + ' from the drawing manager.');
}
else
{
alert('No shapes in the drawing manager.');
}
}
result is:
Retrieved [MapLocation (35.17314901376581, 44.72432011035158)],[MapLocation (35.10324034213123, 44.73015659716798)],[MapLocation (35.12346106720259, 44.90525120166017)],[MapLocation (35.18633788986748, 44.88362186816408)],[MapLocation (35.17314901376581, 44.72432011035158)] from the drawing manager.
How can I get the exact drawn shape details not just the coordinates?
Remove getRings() and you will have the shape object. The Get Rings function retudrrns the coordinates of a polygon.

Find markers shown in mapView

I am trying to determine the marker/s currently shown in a mapview. I have researched the following the method:
self.mapView.bounds.contains(markers[0].position)
But the contains command accepts CGPoint or CGRect. In other platforms except Swift, contains can accept the marker's position.
How do I convert the marker's position to be accepted by contains?
Use the mapview's current projection. Use the projection's method called containsCoordinate to check if you marker's position is inside the projection, i.e. currently visible.
So something like:
let coord = marker.position
let isVisible = self.mapview.projection.containsCoordinate(coord)
https://developers.google.com/maps/documentation/ios-sdk/reference/interface_g_m_s_projection.html#aa6ad29e6831e40f00435c3aaeda8e08a
In MapKit:
I assume with Marker you mean an MKAnnotation. Instead of using the bounds of the mapView you should use the visibleMapRect and see if it contains the coordinates of the Marker in MKMapPoints. This is the code I used:
let markerPoint = MKMapPointForCoordinate(markers[0].coordinate)
if MKMapRectContainsPoint(mapView.visibleMapRect, markerPoint) {
print("Found")
} else {
print("Not found")
}
Only when the coordinates of the markers are visible (in other words, the marker is being displayed), this will print "Found". If off-screen, it will print "Not found".

Gwt Highcharts Marker or Symbol Rotation

I'm testing Gwt Highcharts but I have a big problem: I need to draw a scatter chart with symbol and rotate the symbol.
For example:
Point p1 = new Point(5, 5);
Marker m = new Marker();
m.setEnabled(true);
m.setRadius(4);
String myUrl = "url(" + GWT.getModuleBaseURL()+"images/snow.png" + ")";
m.setOption("symbol", myUrl);
p1.setMarker(m);
This all works fine
The problem is that I need to rotate the symbol by a degree value. I've tried the following code but it doesn't work:
String myRotate = "rotate(45)";
m.setOption("transform", myRotate);
What's wrong?
Thanks a Lot.
Maurizio
This is what we've came up with in our case:
private static native void rotateMarkers(double angle)/*-{
//Accessing the series we'll rotate
var points = $wnd.Highcharts.charts[0].series[3].points;
//rotating
var str = parseFloat(points[i].graphic.attr('x')) +
parseFloat(points[i].graphic.attr('width'))/2 +
","+ (parseFloat(points[i].graphic.attr("y")))+
")";
points[i].graphic.attr("transform","rotate("+angle+","+str);
}-*/;
It didn't work for us in non-jsni way, same way it didn't for you.

Google maps V2 android get current location

Im trying to place a marker on the position i am, this way:
googleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map_container)).getMap();
googleMap.setMyLocationEnabled(true);
My question is, how to get coordinates from myLocation, i tried, googleMap.getMyLocation().getLatitude() and googleMap.getMyLocation().getAltitude() right after googleMap.setMyLocationEnabled(true), but app crashes, another thing i did was Location loc=lm.getLastKnownLocation(provider) but are not the same coordinates and the marker is placed in the wrong place.
How can you people help me?
SupportMapFragment mf =(SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
mMap = mf.getMap();
mMap.setMyLocationEnabled(true);
mMap.setMapType(mMap.MAP_TYPE_NORMAL);
Just add these two lines of code to get current location on Maps
googleMap.setMyLocationEnabled(true);
googleMap.getUiSettings().setMyLocationButtonEnabled(true);
and when you long press on any location on map add this code to get its location
googleMap.setOnMapLongClickListener(new OnMapLongClickListener() {
#Override
public void onMapLongClick(LatLng arg0) {
double alt = arg0.latitude;
double alo = arg0.longitude;
MarkerOptions marker1 = new MarkerOptions().position(new LatLng(alt, alo)).title("Lat ="+alt+" Lang="+alo);
googleMap.addMarker(marker1);
}
});