l am trying to get objects keys from JSON API url , content on latitude and longitude from server . The data json api content on Object keys and those keys are change all time . l want to get only the coordinates inside of those Object keys and add it to leaflet map marker as array then show on map .
protected points: { lng: number, lat: number }[] = [];
Data : any
data(){
this.http.get("xxxxxxxxxxxx",{},{}).
then((data) => {
this.Data = JSON.parse(data.data);
this.points = Object.keys(this.Data)
.map(key => this.Data[key])
.map((position) => ({
lat: position[0],
lon: position[1]
}));
this.points.forEach((point) => {
new L.Marker([point]
Live code
new L.Marker([point]
Should have been:
new L.Marker(point (no need for square brackets)
Your point variable is already a LatLngExpression (in your case: an object with lat and lon properties)
Related
This is how my data is saved inside LiveTracker there is 2,8 which are bus route id and inside it there is auto generated firebase id and inside that id there is latitude and longitude and i wanna access those latitude and longitude but i am stuck at here and dont know how to fetch that data need soo help
This is my data format which i get when i print data
{-NCQE5NU7ajW2L57gt1o: {latitude: -122.07730612330596, longitude: 37.41749912586621}, -NCQF6O3vx2NYVdZKD0X: {latitude: -122.083922, longitude: 37.4214938}, -NCQF6kWJPOyLuymJeXz: {latitude: -122.07730453282453, longitude: 37.417496832888055}, -NCQF5afZXRqg1Heb9Oq: {latitude: -122.07730562660478, longitude: 37.417495975114676}, -NCQDoU67-ZjN4kNEyPr: {latitude: -122.07730474508638, longitude: 37.41749751091001},
this is how i am trying to fetch that latitude and longitude but i am stuck and dont know how to get it
_dbReference?.child("LiveTracker").child(passedId.toString()).onValue.listen((event) {
var data = event.snapshot.value;
print("This is data $data");
/* _markers.add(Marker(
markerId: MarkerId(DateTime.now().toIso8601String()),
position: LatLng(double.parse(event.snapshot.value.toString()),
double.parse(event.snapshot.value.toString()))));*/
});
data appears to be a Map object when you print it. Assuming your app code is aware of the autogenerated IDs, you can fetch latitude and longitude like so:
var data = event.snapshot.value;
var latitude = data['-NCQE5NU7ajW2L57gt1o']['latitude'];
var longitude = data['-NCQE5NU7ajW2L57gt1o']['longitude'];
print("$latitude, $longitude");
If I misunderstood and your issue is not being aware of the auto generated IDs, then you need to either restructure your data or fetch the keys at runtime with: data.keys.toList()
I'm using this function to pull key, latitude, and longitude:
Map<double, double> m2 = (await sheet.values.map.column(3, fromRow: 2)).map(
(key, value) => MapEntry(
double.parse(key), value == null ? null : double.tryParse(value)));
List longitudelist = m2.values.where((value) => value != null).toList();
Latitude is of course pulled with the same, just with columns 2 from row 2.
Column 1 is numebered. one through how ever many points I have...
Is there any way I can simply pull latitude and longitude values and completely ignore keys? I want to be able to have latitude in column 1, longitude in 2, and nothing more.
Sure try to use ForEach( (e) { return Your_Funcation ; }
Check this for more :
https://api.dart.dev/stable/2.9.1/dart-core/Iterable/forEach.html
I am a newbie of Google charts. I am trying to change data type of a google chart data table column after this has been created. Searching for a solution over the internet I have bumped into this solution for a datetype column. May you generalize it in order to change a chosen data type column from number to string? I would like to change it so that I can visualize some strings in a number column, as you can see in the attached screenshot.
My trial is:
<script type="text/javascript">
function drawVisualization() {
$.get("delivery_pl_daily_test.csv", function(csvString) {
// transform the CSV string into a 2-dimensional array
var arrayData = $.csv.toArrays(csvString, {onParseValue: $.csv.hooks.castToScalar});
// this new DataTable object holds all the data
var data = new google.visualization.arrayToDataTable(arrayData);
var columns = [];
for (var i = 0; i < data.getNumberOfColumns(); i++) {
columns.push(i);
}
var view = new google.visualization.DataView(data);
columns[0] = {
calc: row,
label: arrayData[0][0],
type: 'string'
};
view.setColumns(columns);
Thanks in advance.
Drigo
what you have looks close,
but calc should be a function,
that returns the value for the column.
the calc function receives the data table and current row as arguments.
here, I simply return the formatted value of the column.
columns[0] = {
calc: function (dt, row) {
return dt.getFormattedValue(row, 0);
},
label: arrayData[0][0],
type: 'string'
};
New to Dart (Flutter), and the docs don't seem to have a method for the Map class that will allow me to do this easily...
I want to have a Map with keys of Datetime and values of calories eaten.
{'2019-07xxx': 350, '2019-07xxx': 500, ...}
Now, what's the best way to filter this so that I only get values from today? (i.e. when starting the app and pulling the data from storage)
Ideally once I do that, I can get the cumulative value of today's calories so far with:
var sum = todaysCaloriesArray.reduce((a, b) => a + b);
Unless there is some Dart-fu that would allow this in a better way?
You could use .where on the map's entries. For example:
var map = Map<String, int>();
var sum = map.entries
.where((e) => e.key.startsWith('2019-07-22'))
.map<int>((e) => e.value)
.reduce((a, b) => a + b);
The first answer was great! But you can use the fold method so you can use in empty collections.
var map = Map<String, int>();
var sum = map.entries
.where((e) => e.key.startsWith('2019-07-22'))
.fold(0,(int a, b) => a + b.value);
Follow the example on leaflet map (http://leafletjs.com/examples/layers-control.html), I can create a layer group cities, which showed in overlayMaps Cities.
In the later stage (i.e. another function), is it possible to get the object layer group by name cities or Cities? Then I can use it in another function (e.g. leaflet-search (https://github.com/stefanocudini/leaflet-search)).
This is my pseudo code to demo my question
find_layer_by_name = function(name){
// add code here
};
var searchLayer = find_layer_by_name('cities');
var searchcontrol = new L.Control.Search({layer: searchLayer});
Let me know if my question is not clear.
If you have created an overlayMaps object with key/value pairs (as in the Leaflet example), you can use square bracket notation with your key as a string to get the corresponding layer. The following will assign cities to searchLayer:
var overlayMaps = {
"Cities": cities
};
var searchLayer = overlayMaps["Cities"];