Build application using GMap.Net in C# with offline maps - c#

I'm trying to download a MapProvider to use offline map but i dont know how to download.
it works when i use ServerOnly.
This is my code:
GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.ServerOnly;
_map = new GMapControl();
Map.MapProvider = GMap.NET.MapProviders.BingHybridMapProvider.Instance;
Map.DragButton = MouseButton.Left;
Map.MinZoom = 2;
Map.MaxZoom = 18;
Map.Zoom = 5;
Map.CanDragMap = true;
Map.Position = new GMap.NET.PointLatLng(48.8589507, 2.2775175);
Map.ShowCenter = false;
Thank you everyone

You can cache the map in the local storage using the ServerAndCache found in GMap.NET.AccessMode
The following function will do the work:
private void gMapStoreOffline(int lat, int lng)
{
gMapControl1.MapProvider = GMap.NET.MapProviders.BingMapProvider.Instance;
GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.ServerAndCache;
GMap.NET.MapProviders.OpenStreetMapProvider.UserAgent = "IE";
gMapControl1.MapProvider = GMap.NET.MapProviders.OpenStreetMapProvider.Instance;
GMaps.Instance.OptimizeMapDb(null);
// Define the location to cache the file
gMapControl1.CacheLocation = #"C:\Users\<username>\..";
gMapControl1.Zoom = 14;
gMapControl1.Size = new Size(this.Width, this.Height);
gMapControl1.ShowCenter = false;
gMapControl1.Position = new GMap.NET.PointLatLng(lat, lng)
}

Related

requests[0]' (oneof), oneof field 'kind' is already set. Cannot set 'updateCell encountered when generating checkbox

I'm trying to generate a checkbox from C#.net using google sheets API but I'm encountering the oneof field kind is already set error. I tried combining extendedValue and DataValidation. Please see code snippet below:
ConditionValue conditionValueTrue = new ConditionValue();
conditionValueTrue.UserEnteredValue = "TRUE";
ConditionValue conditionValueFalse = new ConditionValue();
conditionValueFalse.UserEnteredValue = "FALSE";
ConditionValue[] validValues = { conditionValueTrue, conditionValueFalse };
BooleanCondition bc = new BooleanCondition();
bc.Type = "BOOLEAN";
bc.Values = validValues;
DataValidationRule dataValidationRule = new DataValidationRule();
dataValidationRule.Condition = bc;
dataValidationRule.ShowCustomUi = true;
GridRange validationRange = new GridRange();
validationRange.StartColumnIndex = 7;
validationRange.EndColumnIndex = 7;
validationRange.SheetId = 0;
SetDataValidationRequest setDataValidationRequest = new SetDataValidationRequest();
setDataValidationRequest.Rule = dataValidationRule;
setDataValidationRequest.Range = validationRange;
ExtendedValue extendedValue = new ExtendedValue();
extendedValue.BoolValue = true;
BatchUpdateSpreadsheetRequest busr = new BatchUpdateSpreadsheetRequest();
busr.Requests = new List<Request>();
Request r = new Request();
busr.Requests.Add(r);
r.UpdateCells = new UpdateCellsRequest();
r.SetDataValidation = setDataValidationRequest;
var gc = new GridCoordinate();
gc.ColumnIndex = 7;
gc.RowIndex = row;
gc.SheetId = 0;
r.UpdateCells.Start = gc;
r.UpdateCells.Fields = "*";
r.UpdateCells.Rows = new List<RowData>();
var rd = new RowData();
r.UpdateCells.Rows.Add(rd);
rd.Values = new List<CellData>();
var cd = new CellData();
cd.UserEnteredValue = extendedValue;
rd.Values.Add(cd);
SpreadsheetsResource.BatchUpdateRequest bur = _sheetsService.Spreadsheets.BatchUpdate(busr, SpreadsheetId);
bur.Execute();

AWS Elemental Media Converter How To Create Job Thumbnail using .Net C#

AWS Elemental Media Converter How To Create Job Thumbnail using .Net C# - I am unable to create the Aws Elemental Media Converter Job using .Net C#. facing the output group exception. I have tried with preset defined facing the same issue using the code and preset...
createJobRequest.Role = mediaConvertRole;
createJobRequest.Queue = jobQueue;
createJobRequest.UserMetadata.Add("Customer", "Amazon");
#region Create job settings
Amazon.MediaConvert.Model.JobSettings jobSettings = new Amazon.MediaConvert.Model.JobSettings();
jobSettings.AdAvailOffset = 0;
jobSettings.TimecodeConfig = new Amazon.MediaConvert.Model.TimecodeConfig();
jobSettings.TimecodeConfig.Source = Amazon.MediaConvert.TimecodeSource.EMBEDDED;
createJobRequest.Settings = jobSettings;
#region Thumbnail
Amazon.MediaConvert.Model.OutputGroup ofgT = new Amazon.MediaConvert.Model.OutputGroup();
ofgT.Name = "Thumbnail";
ofgT.OutputGroupSettings = new Amazon.MediaConvert.Model.OutputGroupSettings();
ofgT.OutputGroupSettings.Type = Amazon.MediaConvert.OutputGroupType.FILE_GROUP_SETTINGS;
ofgT.OutputGroupSettings.FileGroupSettings = new Amazon.MediaConvert.Model.FileGroupSettings();
ofgT.OutputGroupSettings.FileGroupSettings.Destination = fileOutput;
Amazon.MediaConvert.Model.Output outputT = new Amazon.MediaConvert.Model.Output();
outputT.NameModifier = "_thumb_00001";
outputT.Extension = "png";
output.Preset = preset_thumbnail;
#region Mp4 Container
outputT.ContainerSettings = new Amazon.MediaConvert.Model.ContainerSettings();
outputT.ContainerSettings.Container = Amazon.MediaConvert.ContainerType.MP4;
Amazon.MediaConvert.Model.Mp4Settings mp4T = new Amazon.MediaConvert.Model.Mp4Settings();
mp4T.CslgAtom = Amazon.MediaConvert.Mp4CslgAtom.INCLUDE;
mp4T.FreeSpaceBox = Amazon.MediaConvert.Mp4FreeSpaceBox.EXCLUDE;
mp4T.MoovPlacement = Amazon.MediaConvert.Mp4MoovPlacement.PROGRESSIVE_DOWNLOAD;
outputT.ContainerSettings.Mp4Settings = mp4T;
#endregion Mp4 Container
ofgT.Outputs.Add(outputT);
createJobRequest.Settings.OutputGroups.Add(ofgT);
#endregion Thumbnail
#region Input
Amazon.MediaConvert.Model.Input input = new Amazon.MediaConvert.Model.Input();
input.FilterEnable = Amazon.MediaConvert.InputFilterEnable.AUTO;
input.PsiControl = Amazon.MediaConvert.InputPsiControl.USE_PSI;
input.FilterStrength = 0;
input.DeblockFilter = Amazon.MediaConvert.InputDeblockFilter.DISABLED;
input.DenoiseFilter = Amazon.MediaConvert.InputDenoiseFilter.DISABLED;
input.TimecodeSource = Amazon.MediaConvert.InputTimecodeSource.EMBEDDED;
input.FileInput = fileInput;
Amazon.MediaConvert.Model.AudioSelector audsel = new Amazon.MediaConvert.Model.AudioSelector();
audsel.Offset = 0;
audsel.DefaultSelection = Amazon.MediaConvert.AudioDefaultSelection.NOT_DEFAULT;
audsel.ProgramSelection = 1;
input.AudioSelectors.Add("Audio Selector 1", audsel);
input.VideoSelector = new Amazon.MediaConvert.Model.VideoSelector();
input.VideoSelector.ColorSpace = Amazon.MediaConvert.ColorSpace.FOLLOW;
createJobRequest.Settings.Inputs.Add(input);
#endregion Input
Amazon.MediaConvert.Model.CreateJobResponse createJobResponse = mcClient.CreateJob(createJobRequest);
string jobId = createJobResponse.Job.Id;
AWS Elemental Media Converter How To Create Job Thumbnail using .Net C#
This Code solve my problem to generate the thumbnail using Aws elemental media converter. Passing the outoup object with these parameters:
Amazon.MediaConvert.Model.Output outputThumb = new Amazon.MediaConvert.Model.Output();
outputThumb.ContainerSettings = new Amazon.MediaConvert.Model.ContainerSettings { Container = Amazon.MediaConvert.ContainerType.RAW };
outputThumb.NameModifier = "_thumbnail";
outputThumb.Extension = "png";
outputThumb.VideoDescription = new Amazon.MediaConvert.Model.VideoDescription();
outputThumb.VideoDescription.CodecSettings = new Amazon.MediaConvert.Model.VideoCodecSettings();
outputThumb.VideoDescription.CodecSettings.Codec = "FRAME_CAPTURE";
outputThumb.VideoDescription.CodecSettings.FrameCaptureSettings = new Amazon.MediaConvert.Model.FrameCaptureSettings {
MaxCaptures = 1,
Quality = 100
};
ofg.Outputs.Add(outputThumb);

How to Play MJP Files in C# WinForm by using Vlc.DotNet?

How to Play MJP Files in C# by using Vlc.DotNet ? here is my code-
VlcControl player = new VlcControl();
panel1.Controls.Add(player);
player.BackColor = System.Drawing.Color.Aqua;
player.ImeMode = System.Windows.Forms.ImeMode.NoControl;
player.Location = new System.Drawing.Point(0, 0);
player.Name = "test";
player.Rate = 0.0F;
player.Size = new System.Drawing.Size(1024, 768);
player.Play(new FileInfo(#"E:\Sample\2.mjp"));
Try this. It works for me:
private void Play()
{
if (vlcVideo.IsPlaying)
{
vlcVideo.Stop();
}
string path = #"E:\Sample\2.mjp";
LocationMedia media = new LocationMedia(path);
vlcVideo.Media = media;
vlcVideo.Play();
}

app crashes before the request is sent to the server

I'm building an android app with Xamarin which communicates with an ASP.net server's API. I'm trying to upload a file to the server using the following lines of code:
public async Task<HttpResponseMessage> UploadFile(byte[] file)
{
var progress = new System.Net.Http.Handlers.ProgressMessageHandler();
//progress.HttpSendProgress += progress_HttpSendProgress;
using (var client = HttpClientFactory.Create(progress))
{
client.BaseAddress = new Uri(GlobalVariables.host);
// Set the Accept header for BSON.
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/bson"));
var request = new uploadFileModel { data = file, dateCreated = DateTime.Now, fileName = "myvideooo.mp4", username = "psyoptica" };
// POST using the BSON formatter.
MediaTypeFormatter bsonFormatter = new BsonMediaTypeFormatter();
var m = client.MaxResponseContentBufferSize;
var result = await client.PostAsync("api/media/upload", request, bsonFormatter);
return result.EnsureSuccessStatusCode();
}
}
The app crashes before the server receives the request. The file I'm trying to upload could be a video or an audio file. The server receives the request after the app has crashed. This works fine on the local server but the crash happens with the live server. My server side code looks like this:
[HttpPost]
[Route("upload")]
public async Task<HttpResponseMessage> Upload(uploadFileModel model)
{
var result = new HttpResponseMessage(HttpStatusCode.OK);
if (ModelState.IsValid)
{
string thumbname = "";
string resizedthumbname = Guid.NewGuid() + "_yt.jpg";
string FfmpegPath = Encoding_Settings.FFMPEGPATH;
string tempFilePath = Path.Combine(HttpContext.Current.Server.MapPath("~/tempuploads"), model.fileName);
string pathToFiles = HttpContext.Current.Server.MapPath("~/tempuploads");
string pathToThumbs = HttpContext.Current.Server.MapPath("~/contents/member/" + model.username + "/thumbs");
string finalPath = HttpContext.Current.Server.MapPath("~/contents/member/" + model.username + "/flv");
string resizedthumb = Path.Combine(pathToThumbs, resizedthumbname);
var outputPathVid = new MediaFile { Filename = Path.Combine(finalPath, model.fileName) };
var inputPathVid = new MediaFile { Filename = Path.Combine(pathToFiles, model.fileName) };
int maxWidth = 380;
int maxHeight = 360;
var namewithoutext = Path.GetFileNameWithoutExtension(Path.Combine(pathToFiles, model.fileName));
thumbname = model.VideoThumbName;
string oldthumbpath = Path.Combine(pathToThumbs, thumbname);
var fileName = model.fileName;
File.WriteAllBytes(tempFilePath, model.data);
if (model.fileName.Contains("audio"))
{
File.WriteAllBytes(Path.Combine(finalPath, model.fileName), model.data);
string audio_thumb = "mic_thumb.jpg";
string destination = Path.Combine(pathToThumbs, audio_thumb);
string source = Path.Combine(pathToFiles, audio_thumb);
if (!System.IO.File.Exists(destination))
{
System.IO.File.Copy(source, destination, true);
}
Video_Struct vd = new Video_Struct();
vd.CategoryID = 0; // store categoryname or term instead of category id
vd.Categories = "";
vd.UserName = model.username;
vd.Title = "";
vd.Description = "";
vd.Tags = "";
vd.OriginalVideoFileName = model.fileName;
vd.VideoFileName = model.fileName;
vd.ThumbFileName = "mic_thumb.jpg";
vd.isPrivate = 0;
vd.AuthKey = "";
vd.isEnabled = 1;
vd.Response_VideoID = 0; // video responses
vd.isResponse = 0;
vd.isPublished = 1;
vd.isReviewed = 1;
vd.Thumb_Url = "none";
//vd.FLV_Url = flv_url;
vd.Embed_Script = "";
vd.isExternal = 0; // website own video, 1: embed video
vd.Type = 0;
vd.YoutubeID = "";
vd.isTagsreViewed = 1;
vd.Mode = 0; // filter videos based on website sections
long videoid = VideoBLL.Process_Info(vd, false);
}
else
{
using (var engine = new Engine())
{
engine.GetMetadata(inputPathVid);
// Saves the frame located on the 15th second of the video.
var outputPathThumb = new MediaFile { Filename = Path.Combine(pathToThumbs, thumbname+".jpg") };
var options = new ConversionOptions { Seek = TimeSpan.FromSeconds(0), CustomHeight = 360, CustomWidth = 380 };
engine.GetThumbnail(inputPathVid, outputPathThumb, options);
}
Image image = Image.FromFile(Path.Combine(pathToThumbs, thumbname+".jpg"));
//var ratioX = (double)maxWidth / image.Width;
//var ratioY = (double)maxHeight / image.Height;
//var ratio = Math.Min(ratioX, ratioY);
var newWidth = (int)(maxWidth);
var newHeight = (int)(maxHeight);
var newImage = new Bitmap(newWidth, newHeight);
Graphics.FromImage(newImage).DrawImage(image, 0, 0, newWidth, newHeight);
Bitmap bmp = new Bitmap(newImage);
bmp.Save(Path.Combine(pathToThumbs, thumbname+"_resized.jpg"));
//File.Delete(Path.Combine(pathToThumbs, thumbname));
using (var engine = new Engine())
{
var conversionOptions = new ConversionOptions
{
VideoSize = VideoSize.Hd720,
AudioSampleRate = AudioSampleRate.Hz44100,
VideoAspectRatio = VideoAspectRatio.Default
};
engine.GetMetadata(inputPathVid);
engine.Convert(inputPathVid, outputPathVid, conversionOptions);
}
File.Delete(tempFilePath);
Video_Struct vd = new Video_Struct();
vd.CategoryID = 0; // store categoryname or term instead of category id
vd.Categories = "";
vd.UserName = model.username;
vd.Title = "";
vd.Description = "";
vd.Tags = "";
vd.Duration = inputPathVid.Metadata.Duration.ToString();
vd.Duration_Sec = Convert.ToInt32(inputPathVid.Metadata.Duration.Seconds.ToString());
vd.OriginalVideoFileName = model.fileName;
vd.VideoFileName = model.fileName;
vd.ThumbFileName = thumbname+"_resized.jpg";
vd.isPrivate = 0;
vd.AuthKey = "";
vd.isEnabled = 1;
vd.Response_VideoID = 0; // video responses
vd.isResponse = 0;
vd.isPublished = 1;
vd.isReviewed = 1;
vd.Thumb_Url = "none";
//vd.FLV_Url = flv_url;
vd.Embed_Script = "";
vd.isExternal = 0; // website own video, 1: embed video
vd.Type = 0;
vd.YoutubeID = "";
vd.isTagsreViewed = 1;
vd.Mode = 0; // filter videos based on website sections
//vd.ContentLength = f_contentlength;
vd.GalleryID = 0;
long videoid = VideoBLL.Process_Info(vd, false);
}
return result;
}
else
{
throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotAcceptable, "This request is not properly formatted"));
}
}`
What am I doing wrong here that's making the app crash. Is there a better way to do this?
Any help is appreciated.

Creating a source to destination map view for windows phone

I have a default geocoordinate. Another geocoorinate which the user will provide. I want to change the change the map view such such that the source and destination can be clearly seen on the phone window with max zoom possible. Please help on how to approach this problem. I tried using setview() but i coudn't find an overload which could do the task.
public async void ShowMyLocationOnTheMap(string mapvariable)
{
JObject o = JObject.Parse(mapvariable);
string successcallback = o["successCallback"].ToString();
string failutecallback = o["failureCallback"].ToString();
var markerifo = o["markerInfo"];
int count = markerifo.Count();
try
{
for (int i = 0; i < count; i++)
{
drawmap(markerifo[i],"red");
}
Geolocator myGeolocator = new Geolocator();
Geoposition myGeoposition = await myGeolocator.GetGeopositionAsync();
JObject current = new JObject();
current["locationLatitude"] = myGeoposition.Coordinate.Latitude.ToString();
current["locationLongitude"] = myGeoposition.Coordinate.Longitude.ToString();
current["locationDescription"] = "Your Current Location";
current["locationName"] = "";
drawmap(current,"blue");
GeoCoordinate myGeoCoordinate = new GeoCoordinate(myGeoposition.Coordinate.Latitude, myGeoposition.Coordinate.Longitude);
MapAppzillon.SetView(myGeoCoordinate1,6);
gobject.ContentPanel.Children.Add(MapAppzillon);
var jsonstring = "{\"successMessage\":\" Map Displayed \"}";
string[] param = { successcallback, jsonstring };
gobject.invokeScript("StringToJsonObject", param);
}
catch (Exception ex)
{
var jsonstring = "{\"errorCode\":\"APZ-CNT-107\"}";
string[] param = { failutecallback, jsonstring };
gobject.invokeScript("StringToJsonObject", param);
}
}
public void drawmap(JToken markerifo,string color)
{
double latitude = Convert.ToDouble(markerifo["locationLatitude"].ToString());
double longitude = Convert.ToDouble(markerifo["locationLongitude"].ToString());
myGeoCoordinate1 = new GeoCoordinate(latitude, longitude);
Ellipse myCircle = new Ellipse();
if (color == "red")
{
myCircle.Fill = new SolidColorBrush(Colors.Red);
}
else
myCircle.Fill = new SolidColorBrush(Colors.Blue);
myCircle.Height = 20;
myCircle.Width = 20;
myCircle.Opacity = 50;
myCircle.Tap += (sender, e) => myCircle_Tap(sender, markerifo["locationDescription"].ToString(), markerifo["locationName"].ToString());
// myCircle.Tap += myCircle_Tap;
MapOverlay myLocationOverlay = new MapOverlay();
myLocationOverlay.Content = myCircle;
myLocationOverlay.PositionOrigin = new System.Windows.Point(0.5, 0.5);
myLocationOverlay.GeoCoordinate = myGeoCoordinate1;
MapLayer myLocationLayer = new MapLayer();
myLocationLayer.Add(myLocationOverlay);
MapAppzillon.Layers.Add(myLocationLayer);
}
Edit: I tried using dispatcher.Invoke and it finally worked. but now its loading only once . when i press the back button and specify another geocoordinate setview dosent work. Is there any solution to this.
List<GeoCoordinate> the2Points = new List<GeoCoordinate>();
the2Points.Add(myGeoCoordinate1);
the2Points.Add(myGeoCoordinate);
rect = LocationRectangle.CreateBoundingRectangle(the2Points);
gobject.ContentPanel.Children.Add(MapAppzillon);
MapAppzillon.Dispatcher.BeginInvoke(() =>
{
MapAppzillon.SetView(rect);
});
await Task.Delay(150);
You do need to use the SetView method on the Map control. But it needs a BoundingRectangle to work!
So a quick code snippet:
List<GeoCoordinate> the2Points = new List<GeoCoordinate>();
the2Points.Add(point1);
the2Points.Add(point2);
LocationRectangle rect = LocationRectangle.CreateBoundingRectangle(the2Points);
TheMapControl.SetView(rect);

Categories