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!
Related
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.
I have a bunch of markers stored in a mysql database in a table with these attributes id,longitude,latitude.
With an ajax query I get these rows and print to console and they're exactly equal to the ones in the db.
When I create my features with openlayers, with the longitude and latitude retrieved from the db and stored in javascript variables, I don't understand why the markers are placed to another place (they're supposed to be in Italy and they are under Africa).
The interesting thing is that if I manually insert the coordinates while creating the features they show in the right place.
Browsing the internet and trying to debug my code I found some clues.
First, it may be cause of how I store longitude and latitude in the db. I saw there's someone who says DECIMAL(10,8) for latitude and DECIMAL(11,8) for longitude but all of my coordinates are similar to lon: 9.728068 and lat: 44.106414 so i decided to use DECIMAL(7,6) for longitude and DECIMAL(8,6) for latitude.
Second, if I try to console.log the data retrieved from the db I get the right coordinates e.g. 9.728068 and 44.106414 but if I get the coordinates from the features after I created them I get different values.
For the manually inserted coordinates, I get the exact same values, but for the other one no.
Here's a snippet of my code. It's a for loop that in this case will cicle 2 times
var lon = r[i]["Sensor_longitude"]; //getting longitude from success response
var lat = r[i]["Sensor_latitude"]; //getting latitude from success response
console.log(lon); //first time 9.728068, second time 9.728368
console.log(lat); //first and second time 44.106414
//using retrieved coordinates to create the feature
var areaFeature = new ol.Feature({
geometry: new ol.geom.Point(ol.proj.transform([lon,lat], 'EPSG:4326', 'EPSG:3857')),
name: sniffer_name
});
//trying to put manually the coordinates
var iconFeature = new ol.Feature({
geometry: new ol.geom.Point(ol.proj.transform([9.728068,44.106414], 'EPSG:4326', 'EPSG:3857')),
name: sniffer_name
});
console.log(ol.proj.transform(areaFeature.getGeometry().getCoordinates(),'EPSG:3857','EPSG:4326'));
console.log(ol.proj.transform(iconFeature.getGeometry().getCoordinates(),'EPSG:3857','EPSG:4326'));
I have 2 entries in my db which have
lon:9.728068, lat:44.106414
lon:9.728368 ,lat:44.106414
so I will make 4 markers (areaFeature and iconFeature for each entry). areaFeature has the coordinates retrieved from db and iconFeature has coordinates inserted manually.
I expected the first half of logs to be 9.728068, 44.106414 and the second one to be 9.728368, 44.106414 but instead I get this:
9.728068 //correct
44.106414 //correct
[9.728068, -45.893585099999996] //[correct,wrong]
[9.728068, 44.106414] //[correct,correct]
9.728368 //correct
44.106414 //correct
[9.728367999999998, -45.893585099999996] //[wrong,wrong]
[9.728068, 44.106414] //[correct,correct]
As you can see latitude is nearly correct (don't know why it adds so many digits after the point) but it is negative and longitude in the first case is correct but in the second one it has other digits in addition.
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.
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'
});
I'm getting "sick" with in a simply problem. I'm using OpenLayers to display a map with a google map base layer. As an user suggestion i'm doing a request to the google geocode API with an address provided by the user.
The problem:
The google api response is like that:
lat: "-34.8836111"
lon: "-56.1819444"
After that i have to create a LonLat OpenLayers object and make a transformation, like that:
var lonLat = new OpenLayers.LonLat(position.coords.longitude,
position.coords.latitude)
.transform(
new OpenLayers.Projection("EPSG:4326"), //transform from WGS 1984
window.user_map.getProjectionObject() //to Spherical Mercator Projection
);
The problem is that lonLat format is in a different precission.
lat: -4148075.5841099103
lon: -6254145.441513423
I need to have only the first two integers digits that allow that displayable using the google map API (in another page).
Any help? This could be solved in ruby for example in a bebore_save method that formats the coordinates, or in the client side with javascript/jquery
Regards.
Convert numbers to a string:
var myStringLat = 123456.123654 + "";
Then get first two digits:
var myStringLat2Digits = myStringLat.substr(1, 2);
Then convert back to numbers:
var myNumberLat2Digits = Number(myStringlat2Digits, 10);
The problem was solved with a inverse order transformation before showing the second google map.
Like that:
var lonLat = new OpenLayers.LonLat(position.coords.longitude,
position.coords.latitude)
.transform(
window.user_map.getProjectionObject(), //transform from WGS 1984
new OpenLayers.Projection("EPSG:4326") //to Spherical Mercator Projection
);