Log GPS Points to Map - geolocation

Is it currently possible to use GEOLOCATION to enter points or polygons to a map layer, and access that information in form of SHP file, GPX, or KML?
The only examples I currently see render an IMAGE which is pretty much useless from a 'mapping' standpoint.
Thanks

OpenLayers 3 provides everything you need to write such an application. To track a geolocation, you can do something like this:
var geolocation = new ol.Geolocation({
tracking: true
});
var track;
geolocation.on('change:position', function() {
var coordinate = geolocation.getPosition();
if (track) {
track.appendCoordinate(coordinate);
} else {
track = new ol.geom.LineString(coordinate);
}
});
To create a GPX from the track, you can do
var gpx = new ol.format.GPX().writeFeatures([new ol.Feature(track)]);
The gpx variable now holds a string of the serialized GPX document. You can write its content to a file or upload it to a server or do whatever you want to do with it.

Related

YouTube API - retrieve more than 5k items

I just want to fetch all my liked videos ~25k items. as far as my research goes this is not possible via the YouTube v3 API.
I have already found multiple issues (issue, issue) on the same problem, though some claim to have fixed it, but it only works for them as they don't have < 5000 items in their liked video list.
playlistItems list API endpoint with playlist id set to "liked videos" (LL) has a limit of 5000.
videos list API endpoint has a limit of 1000.
Unfortunately those endpoints don't provide me with parameters that I could use to paginate the requests myself (e.g. give me all the liked videos between date x and y), so I'm forced to take the provided order (which I can't get past 5k entries).
Is there any possibility I can fetch all my likes via the API?
more thoughts to the reply from #Yarin_007
if there are deleted videos in the timeline they appear as "Liked https://...url" , the script doesnt like that format and fails as the underlying elements dont have the same structure as existing videos
can be easily fixed with a try catch
function collector(all_cards) {
var liked_videos = {};
all_cards.forEach(card => {
try {
// ignore Dislikes
if (card.innerText.split("\n")[1].startsWith("Liked")) {
....
}
}
catch {
console.log("error, prolly deleted video")
}
})
return liked_videos;
}
to scroll down to the bottom of the page ive used this simple script, no need to spin up something big
var millisecondsToWait = 1000;
setInterval(function() {
window.scrollTo(0, document.body.scrollHeight);
console.log("scrolling")
}, millisecondsToWait);
when more ppl want to retrive this kind of data, one could think about building a proper script that is more convenient to use. If you check the network requests you can find the desired data in the response of requests called batchexecute. One could copy the authentification of one of them provide them to a script that queries those endpoints and prepares the data like the other script i currently manually inject.
Hmm. perhaps Google Takeout?
I have verified the youtube data contains a csv called "liked videos.csv". The header is Video Id,Time Added, and the rows are
dQw4w9WgXcQ,2022-12-18 23:42:19 UTC
prvXCuEA1lw,2022-12-24 13:22:13 UTC
for example.
So you would need to retrieve video metadata per video ID. Not too bad though.
Note: the export could take a while, especially with 25k videos. (select only YouTube data)
I also had an idea that involves scraping the actual liked videos page (which would save you 25k HTTP Requests). But I'm unsure if it breaks with more than 5000 songs. (also, emulating the POST requests on that page may prove quite difficult, albeit not impossible. (they fetch /browse?key=..., and have some kind of obfuscated / encrypted base64 strings in the request-body, among other parameters)
EDIT:
Look. There's probably a normal way to get a complete dump of all you google data. (i mean, other than takeout. Email them? idk.)
anyway, the following is the other idea...
Follow this deep link to your liked videos history.
Scroll to the bottom... maybe with selenium, maybe with autoit, maybe put something on the "end" key of your keyboard until you reach your first liked video.
Hit f12 and run this in the developer console
// https://www.youtube.com/watch?v=eZPXmCIQW5M
// https://myactivity.google.com/page?utm_source=my-activity&hl=en&page=youtube_likes
// go over all "cards" in the activity webpage. (after scrolling down to the absolute bottom of it)
// create a dictionary - the key is the Video ID, the value is a list of the video's properties
function collector(all_cards) {
var liked_videos = {};
all_cards.forEach(card => {
// ignore Dislikes
if (card.innerText.split("\n")[1].startsWith("Liked")) {
// horrible parsing. your mileage may vary. I Tried to avoid using any gibberish class names.
let a_links = card.querySelectorAll("a")
let details = a_links[0];
let url = details.href.split("?v=")[1]
let video_length = a_links[3].innerText;
let time = a_links[2].parentElement.innerText.split(" • ")[0];
let title = details.innerText;
let date = card.closest("[data-date]").getAttribute("data-date")
liked_videos[url] = [title,video_length, date, time];
// console.log(title, video_length, date, time, url);
}
})
return liked_videos;
}
// https://stackoverflow.com/questions/57709550/how-to-download-text-from-javascript-variable-on-all-browsers
function download(filename, text, type = "text/plain") {
// Create an invisible A element
const a = document.createElement("a");
a.style.display = "none";
document.body.appendChild(a);
// Set the HREF to a Blob representation of the data to be downloaded
a.href = window.URL.createObjectURL(
new Blob([text], { type })
);
// Use download attribute to set set desired file name
a.setAttribute("download", filename);
// Trigger the download by simulating click
a.click();
// Cleanup
window.URL.revokeObjectURL(a.href);
document.body.removeChild(a);
}
function main() {
// gather relevant elements
var all_cards = document.querySelectorAll("div[aria-label='Card showing an activity from YouTube']")
var liked_videos = collector(all_cards)
// download json
download("liked_videos.json", JSON.stringify(liked_videos))
}
main()
Basically it gathers all the liked videos' details and creates a key: video_ID - Value: [title,video_length, date, time] object for each liked video.
It then automatically downloads the json as a file.

Extend Azure Map marker on update

I am using Azure Atlas Map in my Azure Web app. I want to move the symbols smoothly without refreshing the whole page.
I did some changes in existing code. I have set a time interval in ajax call and adding the new symbol layer in the map.
But facing issues.
I am getting error
map is undefined.
here is the code
function GetJsonMap(jsondata) {
if (typeof jsondata !== 'undefined') {
var gps_data = jsondata;
for (var i = 0; i < gps_data.length; i++) {
var point = new atlas.data.Point([gps_data[i][0], gps_data[i][1]]);
var feature = new atlas.data.Feature(point, { name: gps_data[i][2], description: '[' + gps_data[i][0] + ", " + gps_data[i][1] + ']' });
datasource.add(feature);
}
//Add a layer for rendering point data as symbols.
var symbolLayer = new atlas.layer.SymbolLayer(datasource, null, {
iconOptions: {
image: 'pin-red'
}
});
debugger;
// $("#iotmap")
map.layers.add(symbolLayer); -->getting error here
}
}
I am calling this GetJsonMap in ajax call.
If you are getting an error that map is null it means that its out of scope in your code. Is it a global or local variable?
Looking at your code I highly recommend that you create the symbol layer after the maps ready event has fired and only create it once. Majority of the code samples for Azure Maps do this. The way your code is now, it will add a new layer every the GetJsonMap function is called. As such, you will end up with several layers over time that are trying to render the same data on the map. Note that the data is managed by the data source, layers only render what's in the data source.
Another tip, you are looping through and adding each point in one by one to the data source. A slightly faster way is to add all the points to an array and then add the array to the data source. Every time data is added to the data source it tries to update the map. Additionally, if you want to overwrite all data on the map, instead of clearing the data source and then adding your data, use the setShapes function of the data source. This will do the clear and add in one function and only trigger a single render update on the map.

How to load multiple ARworld Maps in real world using ARkit2.0 in Unity?

I have been working on UnityARworldMap scene.Trying to load two or more worldmaps(.worldmap extension) which I saved earlier.Starting I load one worldmap,after covering some distance I load second worldmap and the next worldmap after some distance.
I successfully loaded the first arworldmap and prefabs are coming at accurate positions in real world.The problem I faced is when I load the second worldmap the prefabs loaded on the first map changes their position (resets) and loaded at different positons.The reason I believe is that the second map does not contain any position of the prefabs in the first map.Without resetting how to load the other maps along with the first map?
public void Load(string flname)
{
//Loading file from persistent path
Debug.LogFormat("Loading ARWorldMap {0}", Loadpath);
var worldMap = ARWorldMap.Load(Loadpath);
if (worldMap != null)
{
m_LoadedMap = worldMap;
Debug.LogFormat("Map loaded. Center: {0} Extent: {1}", worldMap.center, worldMap.extent);
UnityARSessionNativeInterface.ARSessionShouldAttemptRelocalization = true;
var config = m_ARCameraManager.sessionConfiguration;
config.worldMap = worldMap;
UnityARSessionRunOption runOption = UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors | UnityARSessionRunOption.ARSessionRunOptionResetTracking;
Debug.Log("Restarting session with worldMap");
session.RunWithConfigAndOptions(config, runOption);
// StopPlaneDetection();
}
else
{
Debug.Log("No World Map loaded");
}
}
This is how I load maps after different intervals (given below) .
Load(path+FileName2);//for second world map
Load(path+FileName3);//for third world map
Currently, ARWorldTrackingConfiguration accepts a single world map object only, and to apply it to the scene you reset the session and remove all existing anchors.
For that reason, when you apply the second world map, all anchors from the previous one get removed.
A possible workaround would be to retrieve both world maps and copy all anchors and feature points from one to another and then load the new world map into the scene. But still, this would not be accurate since there are two different snapshots, centers, and extents for each world map which makes relocalization process difficult.
So probably the best option at the moment is to save all anchors in the same world map and prevent loading multiple ones.

How to get/set the bonding box in google map?

How can I get/set the bonding box of a Google map? I know how to create map using center and zoom, but I need a way to save the view of map based on its boxing and the recreate the same view later using the map bonds (NE and SW of map)
Any idea how I can do this?
I am using MVC 3.
You want to use the map.getBounds() function which returns a LatLngBounds object. From this you can then use getNorthEast() and getSouthWest() to get the coordinates you want.
var bounds = map.getBounds();
var NE = bounds.getNorthEast();
var SW = bounds.getSouthWest();
If you need those LatLng objects to then be strings (for inserting to your DB or writing to a cookie or whatever), just use the toString() function on them.
strNE = NE.toString();
strSW = SW.toString();
So let's assume you write these to a cookie or use Ajax to write these to your DB. Once you get them out of the cookie/DB later, you can then just use those for setting the center of the map:
bounds = new google.maps.LatLngBounds(SW, NE);
map.fitBounds(bounds); // or maybe try panToBounds()
All these functions are documented here: https://developers.google.com/maps/documentation/javascript/reference

Monodroid Camera/imageview example

Can someone post an example of how to use the camera, capture the image, preview the image in an image view, compress the image in jpg and upload the bytes to a remote server? The closest I have been able to find is below. We have the camera, and image capture but we need to know how to preview, compress/resize jpg to 640/480px and around 120kb size then upload bytes to a remote server. Thanks to all of you for your help.
http://android-coding.blogspot.com/2010/12/intent-of-mediastoreactionimagecapture.html
Looking at your code there are some things i notice to be wrong:
-[ for the camera functionality ]-
Don't create a file yourself. This is not necessary. Use the ContentResolver.Insert function to give you back a file URI that will contain the picture, just like done here and also take over the isMounted if you want to check if there is external memory present.
You are checking if there's data and then checking if there is a thumbnail. If there's no thumbnail you'll get the full image. That doesn't make sense unless you want to make a thumb of the full version if the thumb is not given back?? Don't you just want to grab the full version or both but not this OR that?
You are retrieving a string value variable to get the URI to the full image? Just save the uri you get from the code in my first point as a property (let's say "myPhotoURI" in the activity class. In the OnActivityResult function that handles your camera intent result just recall that URI and use it as following (Yes, you're seeing it right; i'm not even using the data intent for this just the remembered uri):
Bitmap imageFromCam = MediaStore.Images.Media.GetBitmap(this.ContentResolver, Android.Net.Uri.Parse(myPhotoURI));
To grab an image from the gallery just use the SelectImageFromStorage() function from this question's answer and retrieve the URI of the chosen image in the OnActivityResult check just use:
Android.Net.Uri selectedImageUri = data.ToURI();
That's what worked like a charm for me.
-[sending the data to a webservice ]-
Assuming you're using a WCF or webservice that'll want to receive the image data as a byte array; the approved answer to this question gives a nice example of how to convert your image to an byte array (which is what a WCF webservice wants, anyway)
I think that these directions will get you going.
here is the closest example to date... this brings back Null data when the extra output is used. Still trying to get access to the full image/photo and not a thumbnail.
private void saveFullImage() {
Intent intent = new Intent(Android.Provider.MediaStore.ActionImageCapture);
string file = System.IO.Path.Combine(Android.OS.Environment.DirectoryDcim.ToString(), "test.jpg");
var outputFileUri = Android.Net.Uri.Parse(file);
intent.PutExtra(Android.Provider.MediaStore.ExtraOutput, outputFileUri);
StartActivityForResult(intent, TAKE_PICTURE);
}
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
if (requestCode == TAKE_PICTURE)
{
Uri imageUri = null;
// Check if the result includes a thumbnail Bitmap
if (data != null)
{
if (data.HasExtra("data"))
{
var thumbnail = data.GetParcelableArrayExtra("data");
// TODO Do something with the thumbnail
}
}
else
{
var outputFileUri = data.GetParcelableArrayExtra("outputFileuri");
// TODO Do something with the full image stored
// in outputFileUri
}
}
}

Resources