I have a project which involve me to map some random objects in NYC(Astoria Park, etc).
Now I'm using openalayer3 and osm to display a map, but I having a hard time understanding how to calculate coordinates for NYC.
I have made a map, but it is focused on city of London:
var city = ol.proj.transform([-0.12755, 51.507222], 'EPSG:4326', 'EPSG:3857');
Coordinates for Astoria Park(40.780229N, 73.920935W), but obviously this are not the coordinates that I'm locking for, I have read about ol.proj.transform, but I can't understand how to calculate this.
Can someone explain me how can I overcome this and learn something, thank you.
OpenLayers uses coordinates in the form of longitude, latitude. 40.780229,-73.920935 are the correct coordinates for Astoria Park, New York, however in latitude, longitude. Try var city = ol.proj.transform([-73.920935, 40.780229], 'EPSG:4326', 'EPSG:3857'); instead.
Related
I'm new to OSM and would like to know if my approach for finding the next intersection ahead is possible when doing it offline.
The goal is to get the coordinates (latitude/longitude) of the next intersection on the street I'm currently driving on. For that I have my actual position (lat/lon coordinates) and heading (w.r.t. the north-pole) at disposition.
My current approach right now is to first use my coordinates for getting the name of the street/way/trace in which I am driving; then use that name for knowing which are the next intersections on that street (to both sides); and then use the heading for knowing which direction is the one I should pay attention to.
Once I have the intersection, I would get its coordinates and continue with the program.
My questions are then, is it possible to do all of that offline, i.e. with a .osm file (or similar)?
And, do you know a better approach for getting the coordinates of the next intersection ahead?
Thanks a lot in advance!
PS. I was able to get the name of the street by using nominatim and to get all the intersections of a street by using Overpass turbo, but this solutions would need internet; or is there a way of using them offline?
I'm using React Leaflet. When a user clicks on the map, I retrieve the coordinates and a marker is set on that. Everything works on the map, but the map is used as a way to retrieve weather data for the set location.
Explanation
Here is a picture which might help illustrate the problem I'm facing
At the top I added longitudes values for each "piece" of earth.
There is a marker with "true" longitude which is -0.09°
On the left earth, the same location would return -360.09° longitude
On the right earth, the same location would return 359.91° longitude
I retrieve latitude and longitude with this piece of code:
setMarker = e => {
this.props.updateLocation({
lat: e.latlng.lat,
lng: e.latlng.lng,
})
}
The problem
The problem I'm facing is, if I pass down a longitude value to the weather API thats out of the allowed ranges (> -180° && < 180°), it doesn't return anything, cause that longitude, of course, doesn't exist.
Is there a method that returns the "true" latitude and longitude?
If this doesn't exist, how can I disable the map scrolling (allow only one earth to appear)? Or just allow placing a marker inside the first earth? I am unsure what is the best approach for this, and the leaflet documentation is confusing me as I don't understand some of the terminology.
After more searching I have found a built in method that does exactly what i want it to.
Found it on this GitHub issue https://github.com/Leaflet/Leaflet/issues/1885#issuecomment-91395167
To get actual latitude and longitude on a mouse click, no matter on which earth you click, you use the wrap() method on latlng:
event.latlng.wrap()
This returns an object, e.g.
{
lat: 63.51385990617828,
lng: 173.671875
}
So I have an app with a MapView and I use CoreData to load annotations associated with locations nearby the center of the map. Currently, I define the lat/long range statically like this:
var fetchDataPredicates = [NSPredicate]()
fetchDataPredicates.append(NSPredicate(format: "itemLatitude BETWEEN {%f,%f} AND itemLongitude BETWEEN {%f,%f}", (latitude-0.10), (latitude+0.10), (longitude-0.10), (longitude+0.10)))
However, this is a pretty poor solution. If the user has zoomed out far in the map then the data would only cover a small portion of it.
Does anyone have any good ideas on how to dynamically adjust the lat/long range according to the MapView bounds?
Thanks!
A likely solution would be to ask the map view for its region. That's an MKCoordinateRegion which includes
CLLocationCoordinate2D center
MKCoordinateSpan span
The span includes longitude and latitude deltas, which look like exactly what you need.
Given is a DB full of parent/child relationships of political district geo data/names:
Country
State
District
Now I'm querying for that data, building a string like germany,bavaria,ebersberg and then I try to fetch the lat/lng center of that district via the Nominatim API (part of OpenStreetMaps).
Example String:
http://nominatim.openstreetmap.org/search?format=xml&polygon=0&addressdetails=0&q=germany,bavaria,ebersberg
Problem is, that I get back a bunch of POIs with lat/lng instead exact geographical data. This often results in having exact the half of that district displayed as the first POI could be close to that districts border.
Does anyone know of a way to get the lat/lng of the center or how to center a OSM map? OR does anyone know of an alternate API that can achieve this and tell how it works/make an example?
Does anyone know of a way to get the lat/lng of the center or how to center a OSM map?
When you get a bunch (list, set) of points of interest with latitudes and longitudes, you have a feature, not a problem.
You iterate through the POI, building a bounding rectangle that includes all of the POI. In other words, you find the minimum latitude, minimum longitude, maximum latitude, and maximum longitude.
You find the center of the rectangle by the formula
(maximum + minimum) / 2
The bounding area should be small enough that you're not going to incur much error working with latitude and longitude.
Otherwise, you can calculate the distance between the minimum latitude, longitude and the maximum latitude, longitude. The center is half the distance from the minimum latitude, longitude. Convert that center point back to a latitude and longitude for your answer.
This should be quite simple but I am not getting it.
I have a database of locations with lon/lat specified.
After loading the bing map I get the bounds
var view = map.getBounds();
and then call a webmethod to get all the locations which should be shown (within the bounds of the visible map).
I cannot figure out a query to get the locations (which all have a lon/lat specified) .
This obviously does NOT work as when negative values come into play they mess up the query:
SELECT Location_name, longtitude, latitude FROM location_view WHERE latitude< '40.112' and latitude> '35.783' and longtitude< '28.10453' and longtitude> '19.315'
Is there a normalized way to do this? So the comparison would work?
Your query will work absolutely fine with negative values: a longitude of -130 is still west of a longitude of -120. The only situation in which it won't work is if the bounds of your map crosses the 180th meridian. I.e. the "westmost" longitude is 170 and the "eastmost" latitude is -170.
What database are you using? If you're using SQL Server then you can define each of your locations as a Point using the geography datatype. The geography datatype operates on a round model of the earth, so it will account correctly for crossing the 180th meridian with a query like this:
SELECT Location_name
FROM location_view
WHERE location.STIntersects('POLYGON((19.315 35.783, 28.10453 35.783, 28.10453 40.112, 19.315 40.112, 19.315 35.783))') = 1;