Google Map marker coordinate string to number - asp.net-mvc

I am trying to create a Google Map with a single coordinate as marker. I use ASP MVC, and the coordinates are saved in the database as a string.
<%: Model.LatLng %>
outputs something like this: 52.425, 4.938
The problem is, Google Maps cannot read this, probably because it is a string. How do I convert the coordinates to something Google Maps can read?
Google map code (just default example)
var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
var myOptions = {
zoom: 4,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title:"Hello World!"
});
mylatlng needs to be <%: Model.LatLng %> but since its a string it won't work.

Got the anwser:
var LatLng = "<%: Model.LatLng %>";
var latlngparts = LatLng.split(",");
var latlng = new google.maps.LatLng(parseFloat(latlngparts[0]), parseFloat(latlngparts[1]));

Related

CopyTo Google sheets

I'm trying to get this code to work but keep getting a "TypeError: offset.copyTo is not a function". The script is supposed to take one value from sheet "Budget" and copy it into the next available row in column F on sheet "Projected".
I have tried playing around with syntax and other ways to copy but to now avail, any help would be greatly appreciated
function OffsetRecord() {
var sheet = SpreadsheetApp.openById("xx").getSheetByName("Budget");
var offset = sheet.getRange('I5').getValue();
var destSheet = SpreadsheetApp.openById("xx").getSheetByName("Projected");
var colF = destSheet.getRange('F:F').getValues();
var fcolF = colF.filter(function (e) {return e[0];});
var firstEmptyRowIncolF = fcolF.indexOf('')+1;
offset.copyTo(firstEmptyRowIncolF, {contentsOnly: true});
copyTo expects ranges as parameters, not values or column numbers, see here
Modify your code as following:
function OffsetRecord() {
var spreadsheet = SpreadsheetApp.openById("XX");
var sheet = spreadsheet.getSheetByName("Budget");
var offset = sheet.getRange('I5');//without ".getValue();"!
var destSheet = spreadsheet.getSheetByName("Projected");
...
firstEmptyRowIncolF = ...;
var destinationColumn = 1;
var range = destSheet.getRange(firstEmptyRowIncolF, destinationColumn);
offset.copyTo(range, {contentsOnly: true});
}

How to export long time series of multiple locations from Google Earth Engine

I would like to export as csv of NDVI time series for different points. I currently have a code that can print a chart, then click download the data from chart. Is there a better way to do so as I do not necessarily need to open a chart?
What I have now is a code to print a chart for one location, then I could download...I would like to have an automatic way so that I will not need to download from chart.
var point = ee.Geometry.Point([-100, 50]);
var LS8 = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA');
var FieldLS8 = LS8.filterBounds(point).filterDate('1995-01-01', '2018-12-31').sort('CLOUD_COVER')
var cloudlessNDVI_LS8 = FieldLS8.map(function(image) {
var cloud = ee.Algorithms.Landsat.simpleCloudScore(image).select('cloud');
var mask = cloud.lte(50);
var ndvi = image.normalizedDifference(['B5', 'B4']).rename('NDVI');
return image.addBands(ndvi).updateMask(mask);
});
print(ui.Chart.image.series({
imageCollection: cloudlessNDVI_LS8.select('NDVI'),
region: point,
reducer: ee.Reducer.first(),
scale: 30
}).setOptions({title: 'LS8: Meadow Cloud-masked NDVI over time'}));
You can do it with the .getRegion command. It outputs an Array with all the values overlapping your geometry, so you can use multipoint geometries as well.
The difficulty is in exporting it, since only FeatureCollections can be exported. That's why you need to convert it to a FeatureCollection to export it.
var points = ee.Geometry.MultiPoint(
[[16.5, 11.3],
[20.9, -14.5]]);
var LS8 = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA');
var FieldLS8 = LS8.filterBounds(points).filterDate('1995-01-01', '2018-12-31').sort('CLOUD_COVER')
var cloudlessNDVI_LS8 = FieldLS8.map(function(image) {
var cloud = ee.Algorithms.Landsat.simpleCloudScore(image).select('cloud');
var mask = cloud.lte(50);
var ndvi = image.normalizedDifference(['B5', 'B4']).rename('NDVI');
return image.addBands(ndvi).updateMask(mask);
});
var poiArray = cloudlessNDVI_LS8.select('NDVI').getRegion(points, 30);
var names = poiArray.get(0)
var values = poiArray.slice(1)
var exportFC = ee.FeatureCollection(
values.map(function(values){
return ee.Feature(null, ee.Dictionary.fromLists(names, ee.List(values)))
})
)
var sortedFC = exportFC.sort('id')
print(sortedFC)
Export.table.toDrive(sortedFC)
You will get an Array with the lon/lat of the point as an identifier, which you could group your graphs by.

How do I check if location is on the polyline (Here maps)?

I search a method to find if my current location is on the path define by aPolyline.
In google maps a function exist isLocationOnEdge, but I cannot find a similar function in Here maps API.
This could be achieved using an approach an below
//global variable
var polyline;
polyline = new H.map.Polyline(strip);
map.addObject(polyline);
function liesOnPolyline(coords){
// get objects at the coordinates (pixel coordinates, can be converted from lat, lon using map.geoToScreen )
var objects = map.getObjectsAt(coords.x, coords.y);
// iterate through the array to check if polyline can be retrieved here
var withinPolyline = false;
for (var object in objects) {
if(objects[object] === polyline){
withinPolyline = true;
break;
}
}
console.log("lies within Polyline"+withinPolyline );
}

how to get coordinate lon lat from geoserver with openlayers3

I run this code to get all of my vector coordinates:
var ft = vectorSource[0].getFeatures();
for(var i=0; i< ft.length; i++){
document.getElementById('abc').innerHTML+=vectorSource[0].getFeatures()[i].getGeometry().transform('EPSG:3857','EPSG:4326').getCoordinates()
};
This is the result:
106.68594471683284,-6.145608605008391,106.68637254034257,-6.145584973628701
How can I get two numbers representing lon & lat from my vector?
i need result coordinate like following code from all my vector but without click the map
map.on('singleclick', function(evt) {
var coordinate = evt.coordinate;
});

Convert point to lat lon

I wonder, how can I get map click event's coordinates as lat,lon?
Here is my code:
map.on('click', function(evt) {
var element = popup.getElement();
var coordinate = evt.coordinate;
var latLon = ol.proj.transform(coordinate, 'EPSG:3857', 'EPSG:4326');
$(element).popover('destroy');
popup.setPosition(coordinate);
Normally, coordinate value gives me an array etc: [48654.02545, 3265468.45455]
But I need lat lon etc:([39,54876,32,547821])
Abstract: I need to convert epsg:3857 coordinate to epsg:4326 coordinate (lat/lon)
Any idea?
If your map view projection is Web Mercator (EPSG:3857), which is the default, then the following should work:
map.on('click', function(evt) {
var lonlat = ol.proj.transform(evt.coordinate, 'EPSG:3857', 'EPSG:4326');
var lon = lonlat[0];
var lat = lonlat[1];
// …
});

Resources