Geo Lat/Lng normalize in Javascript - javascript

Hello I have the problem that i use leaflet and I dont boundbox the map.
Now if an user is drag the map and going out of the normal -180 to 180 lng or -90 to 90 lat my markers dont shown at the new location.
The marker will requested from an api I have written.
Where I use the boundbox coordinates. The problem now is, that I send something like:
lat_min:-23.563987128451217
lat_max:70.61261423801925
lon_min:-343.828125
lon_max:136.40625
to my script and I don't know how i can normalize the coordinates correct to pass the degrees.
EDIT 24.10.2016 01:33 UTC
My MySQL use between:
geolat: {
$between: [lat_min, lat_max]
},
geolon: {
$between: [lon_min, lon_max]
},
Thank you for your hints and tips.

Dude leaflet itself provides wrapLatLng which can be used as map.wrapLatLng(latLngPoint), this returns normalized form of latitude longitude how we need.

Related

How can you get coordinates of a country in Javascript?

I am making a react native app which includes a map and want to place markers at the centres of different countries. However to create each marker you must provide a set of coordinates so I need a function to which I can pass a country name and it returns the coordinates for somewhere in that country (either of its centre or its capital would be good).
getCoords = (country_name) => {
return coords {
latitude: lat_of_country_centre
longitude: long_of_country_centre
}
}
Does anyone know of a function or api that does this?
You would want to use a geocoding API like OpenCageData to convert a country name into a country.
For example, using OpenCageData, the request https://api.opencagedata.com/geocode/v1/json?key=YOUR_KEY&q=Germany would return a JSON object which contains various information about that location name.
In this case, the coordinates would be located at the path in the JSON object results[0].annotations.DMS, which contains lat and lng, latitude and longitude coordinates in degrees, minutes, and seconds (e.g.) 51° 5' 0.31056'' N for latitude and 10° 25' 24.40884'' E for longitude.
Experimentation with this API or others like it may help you find data that is the best for your specific application.
I would take a look at the Google Maps API. That’ll give you a good starting point.
you can take data from google i.e lat and long coords.
and load to your spreadsheet and write a simple program and load this into the array.

Altitude parameter in Earth view on Google Maps

If I go to:
https://www.google.com/maps/#36.9644841,-122.0149787,37m/data=!3m1!1e3?hl=en-US
Please note the 37m parameter after the latitude, longitude. Now if I modify it to 20m (I guess it means meters) like this:
https://www.google.com/maps/#36.9644841,-122.0149787,20m/data=!3m1!1e3?hl=en-US
now I get an even closer zoom of that location. I guess it's the height from which the user sees that location...
What is the corresponding parameter of this in Google Maps Javascript API?
Thanks
Google earth API's are already deprecated and will continue to work for next few days.
So we are left with Google Maps API only. So I will answer according to that only.
What you are trying to do can be achieved by zoom level in google maps, for example
var gMap = new google.maps.Map(
document.getElementById('map-canvas'),
{ zoom : 14 } //Setting default zoom level
);
//To set map to next zoom level
gMap.setZoom(12);
Check this for more details
https://developers.google.com/maps/documentation/javascript/3.exp/reference

How to show mouse position of latituds and logituds to MGRS in Openlayers3?

I have integrated openlayers3 in my project and it shows mouse position into latitudes and longitudes format.
What I want is to show mouse position in MGRS format as well.
How to do that please help.
Demo Here
The MousePosition control takes an optional coordinateFormat function, that takes the coordinate as an argument and returns a formatted string.
You could write your own or use a built in. I'm not sure what you mean by "GPS format", but assuming that it is the latitude and longitude in hours, minutes and seconds as produce by ol.coordinate.toStringHDMS.
var mousePositionControl = new ol.control.MousePosition({
coordinateFormat: ol.coordinate.toStringHDMS,
projection: 'EPSG:4326'
});

ArcGIS initial map location jsapi

I am trying to use a customers ArcGIS system to render a map on a page using the ArcGIS Javascript API.
To define a map in examples it displays:
map = new Map("map",{
basemap: "topo",
center: [-117.19,34.05], // lon, lat
zoom: 13
});
however this is showing fixed co-ordinates.
I want to be able to hit the RESTAPI in the customers internal system with a land id and return and plot the co-ordinates.
Currently I am retrieving a Degree Minute Second latitude and longitude from the land but wondering if there is a simpler way then having to get these values as a string, split them into degrees minutes seconds and then making a calculation to get their X,Y values to plot into this function to define a map.
Essentially I am just trying to load a map in a location specified by the land id and then after load map layers on top, all through the the local systems RestAPI and the Javascript API.
Thanks,
This is all about spatial reference(i.e 102100, 4326 etc) of the map.
Whatever you will add above snippet code this will add a map with basemap (topology) and center of the map will be co-ordinates which you have provided.
if you want to add a point to map and it has different format of geometry then you can use project geometry operation to convert.
require([
"esri/tasks/ProjectParameters", ...
], function(ProjectParameters, ... ) {
var params = new ProjectParameters();
params.geometries = [point];
params.outSR = outSR;
params.transformation = transformation;
gsvc.project(params);
...
});
For Reference: https://developers.arcgis.com/javascript/jsapi/geometryservice-amd.html#project
Convert Degree minute second to decimal/Lat long:
function ConvertDegreeAngleToDecimal(degrees, minutes, seconds )
{
//Decimal degrees =
// whole number of degrees,
// plus minutes divided by 60,
// plus seconds divided by 3600
return degrees + (minutes/60) + (seconds/3600);
}
Hope this will help you.
Let me know if you need more clarifications!

Calculating the bounding box using Javascript

I have a latitude/longitude value and distance value. I need to calculate a bounding box with the given location as the center. so if the distance was 200 meters then the rectangle box should be 200 meters in front, behind, to left and right.
How do I go about doing this using JavaScript?
You need to translate your coordinate lat/long to a x/y-value in the map projection you are using, then you can calculate your bounding box.
I don't know the Google Maps API well, and I don't know exactly what you want to do with your box. But maybe GBounds, GMercatorProjection and GLatLngBounds can be helpful. And if Google Maps API doesn't support calculations for the map projection you are using, then it can be helpful to use Proj4js. And maybe you want to read up about Map projections. Google Maps is by default using Mercator projection.
Here are a number of useful javascript functions for working with latitude and longitude:
http://www.movable-type.co.uk/scripts/latlong.html
For bounding box around a point, a simple modification using the above javascript library might be:
LatLon.prototype.boundingBox = function (distance)
{
return [
this.destinationPoint(-90, distance)._lon,
this.destinationPoint(180, distance)._lat,
this.destinationPoint(90, distance)._lon,
this.destinationPoint(0, distance)._lat,
];
}
(This uses the "Destination point given distance and bearing from start point" calculation.)
If you're using the V3 API, you can make use of Rectangle and Circle. See this blogger's brief description and examples:
http://apitricks.blogspot.com/2010/02/rectangle-and-circle-of-v3.html

Categories