Get Latitude and Longitude of upper left corner of a Bing Map - bing-maps

I programatically create requests to dev.virtualearth.net (Bing static maps).
I know the following values:
Center Point (Latitude & Longitude)
Zoom Level
Map Size (X pixels, Y pixels)
After I recieved the map as a bitmap, how do I determine the Coordinates (Latitude and Longitude) of the upper left corner (basically the very first pixel) and the lower right corner (the very last pixel)?
I just need some suggestions or some pseudo code. Note, that while I know the Center Point, Zoom Level and Map Size, these aren't the same for every request.
Thank you.

You will need to do tile math: https://msdn.microsoft.com/en-us/library/bb259689.aspx
You will need to do the following:
Pass the center point into LatLongToPixelXY method to get the center global pixel value.
Knowing the pixel dimensions of the static image you created, subtract half the width from the x value of the center global pixel value. Do the same with the height and y.
This gives you a new pixel value, pass it into the PixelXYToLatLong to get the coordinate for the top left corner.
That's it :)
I have an old code sample that does this, but retrieves the static image using the old SOAP services rather than the REST services. You can find the blog post here: https://rbrundritt.wordpress.com/2008/10/25/ve-imagery-service-and-custom-icons/ See the LatLongToPixel function code that is half way down the post. That does the above three steps.

Related

How do I Convert an OpenLayers Polygon to a Circle?

I have a drawing feature where, as in one case, a person can draw a circle using the methodology in OL docs example. When that's saved, the server needed to be have it converted to a polygon, and I was able to do that using fromCircle.
Now, I'm needing to make the circle modifiable after it's been converted and saved. But I don't see a clear cut way to get a Circle geometry out of the Polygon tools provided in the library. There is a Polygon.circular, but that doesn't sound like what I want.
I'm guessing the only way to do this is to grab the center, and one of the segment points, and figure out the radius manually?
As long as fromCircle used sides set to a multiple of 4 and rotation zero (which are the default) center and radius can be easily obtained to convert back to a circle:
center = ol.extent.getCenter(polygon.getExtent());
radius = ol.extent.getWidth(polygon.getExtent())/2;

ARKit: Plot a Node at a specific pixel at a specific Z distance from Camera

Referring to the image above. I have a Red Node at the center of the screen with a distance of 1.0 unit (1 meter away) [See iPhone Portrait Top View]
What I do is I capture a screenshot of the iPhone screen and the resulting image is 750 x 1334 pixels [See iPhone Portrait Front View]
sceneView.snapshot()
What I want to do is put 4 Red Square Nodes located on the four sides of the iPhone screen relative to the Red Circle (at the dead center of the screen). I am making this to mark where I did a snapshot. What I want to know is how can I plot a box node precisely at a certain x,y point given z distance. (The value of Z is not fixed, I just used 1.0 as a sample scenario).. I want to plot (0,0), (750,0), (0, 1334) and (750, 1334) at a given z of 1.0 and assuming I am on a tripod, the plotted nodes would appear on the four sides of my iPhone screen.
I am very terrible at math and this problem is so complicated for me to solve alone with my current math skills. Can anyone help? Please?
Since you need ARnchor nodes (to mark where a snapshot was done) using the real time information from the camera instead of a snapshot would be probably easier. In special due to pixels in a 2D image are referenced from left to right and from top to bottom (with "0,0" coords located in the top left side)
... and we know the AR nodes are referenced in 3D coordinates with the center of the local node as the 0,0,0 coords.
I haven't yet code to test but I think the following properties should help:
let pPoint = sceneView.projectPoint(self.centerBall.position)
let fieldW = sceneView.session.currentFrame?.camera.imageResolution.width
let fieldH = sceneView.session.currentFrame?.camera.imageResolution.height
The "pPoint" should return the 2D coords corresponding to the (0,0,0) 3D coords of "centerBall" from there it should be just add or subtract calculations to obtain all 4 corners in 2D
Finally passing the 2D coords of every corner to the "unprojectPoint(:)" method should provide the 3D "world" coords and that can be converted to "centerBall" coordinates with the "convertPosition( position: SCNVector3, from node: SCNNode?)" method
It seems interesting so will try to code this before weekend
At the end I suspect ARanchor nodes may not be 100% stables

How to Calculate Tiles Coordinates in Leaflet to Request TMS Server?

In order to cache tiles for off-line use, I tried to calculate tiles coordinates according to a certain zoom level. Calculated x coordinates were correct but the y coordinates Were not.
This Old example compares actually received coordinates with that calculated. (click in the map to display results)
I was using map.project(latlng,zoom) to get the projected coordinates and then divide by tileSize which is 256. is this approach even correct ?
EDIT :
Thanks to Ivan Sanchez for the orientation about y inversion in TMS. Actually after projecting the point with map.project(latlng,zoom) you need to inverse the y coordinate as follow :
You calculate _globalTileRange(zoom) for the corresponding zoom level, then
InvertedY = _globalTileRange(zoom).max.y - y ;
Here is another Link that shows the correct calculation of y coordinates for the current zoom of the map, for other zoom levels the globalTileRange need to be recalculated accordingly.
Regards,
Your approach is correct. However:
In order to get the tile coordinates loaded by Leaflet, you are looping through all the loaded images and outputting the min/max of those values.
The problem with this approach is that Leaflet doesn't immediately unload off-screen tiles. See the keepBuffer option, bug #4039 and PR #4650.
In order to fetch the bounds of tiles visible within the map bounds, see the private methods used internally by L.GridLayer around this line of code.
In TMS, the y coordinate goes up, and in non-TMS tiles it does down. This is because TMS was done by geographers, where the y coordinate is the northing, and non-TMS tiles were initially done by computer programmers, who interpret the y coordinate as downward pixels.
For more background, read https://wiki.openstreetmap.org/wiki/TMS#The_Y_coordinate and https://wiki.osgeo.org/wiki/Tile_Map_Service_Specification#TileMap_Diagram and https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#X_and_Y

Layout GPS coordinates without using a map

I'm trying to create a view that present a bunch of coordinates without using a map.
The user's coordinates should be at the center of the screen(in the middle of the circle),
and the rest of the coordinates will be layout relative to one another according to their real latitude and longitude.
Something like this:
I understood that I can't do this with MKMapKit because it will be a violation of Google license, so I need a way to place and manage the coordinates myself.
What is best practice to do something like this? how should I convert the coordinates to a screen points?
I'd go about it as follows:
1) I'd start by normalizing at the user's current location (translate it to 0,0 then apply the same translation to the rest of the coordinates).
2) Once you've done that, use a distance function to find out which coordinate in your list is furthest away from your current location.
3) Use the furthest away coordinate to determine the scale of your view.
4) Calculate the X & Y screen coordinates of all your locations based on the scale you come up with in #3

Longitude, Latitude to XY coordinate conversion

I want to now how to convert longitude, latitude to its equivalent xy coordinate components in iPhone programming. (I am using only CoreLocation programming, and want to show a point on iPhone screen without any map).
thanks
Well the exact conversion depends on exactly which part of the Earth you want to show, and the stretching along longitude varies according to latitude, at least in Mercator.
That being said, even if you don't want to display an actual MapKit map, it would probably be easiest to create an MKMapView and keep it to one side. If you set the area you want to display appropriately on that (by setting the region property), you can use convertCoordinate:toPointToView: to map from longitude and latitude to a 2d screen location.
Note that MKMapView adjusts the region you set so as to make sense for the viewport its been given (eg, if you gave it a region that was a short fat rectangle, but the view it had was a tall thin rectangle, it'd pick the smallest region that covers the entire short fat rectangle but is the shape of a tall thin rectangle), so don't get confused if you specify a region with the top left being a particular geolocation, but then that geolocation isn't at the exact top left of the view.