Windows Phone 7.5 - How to calculate route on map image? - image

In my app for WP7.5, user can navigate into the university. He can see on the map his initial position acquired by scanning a Qr Code. Map image is Canvas background. Once he chooses the destination whose X and Y coordinates are known, how can I draw on the map the route from user's current location to the destination? I don't know if it is possible.
This is the working code that allows to show user's starting position on the map.
public void MarkLocation(ImageBrush imgmap, int posizioneX, int posizioneY)
{
Canvas.Background = imgmap;
Image imgmarker = new Image();
imgmarker.Source = new BitmapImage(new Uri("Images/marker.png", UriKind.Relative));
Canvas.SetLeft(imgmarker, posizioneX);
Canvas.SetTop(imgmarker, posizioneY);
Canvas.Children.Add(imgmarker);
}
I hope you can help me! Thanks in advance.

If you used the BingMapsDirectionsTask (in WP7) or the MapsDirectionsTask (in WP8) and the user will get a full navigation experience including showing the route and you'll not need to worry about dynamically generating images or overlaying items on a Map control.

Related

Best way to show many mini versions of painted InkCanvas in UWP

I have a problem to depict many mini-versions of my InkCanvas. In my app it is possible to write or draw on a InkCanvas. Now I want to depict all created InkCanvas in a GridView.
But with mini versions in this GridView i can not create enough mini versions.
I tested it with 36 mini versions and after I show one and navigate back, the App crashs everytime by rendering the same mini InkCanvas with the error: Insufficient Memory. So I searched an found this post:
Insufficient memory to continue the execution of the program when trying to initialize array of InkCanvas in UWP
I checked the Memory workload:
var AppUsageLevel = MemoryManager.AppMemoryUsageLevel;
var AppMemoryLimit = MemoryManager.AppMemoryUsageLimit;
and the memory has enough free space. (is this a bug?)
So I tried to render a image from my grid with a InkCanvas but the strokes were not rendered and all pictures were empty. ( can I save Memory this way?)
So now my question is:
Can someone tell me how to solve this problem? And what is the best way?
Thank you very much in advance!
Agredo
If you want to preview your drawings, better way is to render them to bitmap and show this bitmaps in grid instead of multiple complex controls InkCanvas is.
Here is some code to render inks to bitmap from another SO Answer:
CanvasDevice device = CanvasDevice.GetSharedDevice();
CanvasRenderTarget renderTarget = new CanvasRenderTarget(device, (int)inkCanvas.ActualWidth, (int)inkCanvas.ActualHeight, 96);
using (var ds = renderTarget.CreateDrawingSession())
{
ds.Clear(Colors.White);
ds.DrawInk(inkCanvas.InkPresenter.StrokeContainer.GetStrokes());
}
using (var fileStream = await file.OpenAsync(FileAccessMode.ReadWrite))
await renderTarget.SaveAsync(fileStream, CanvasBitmapFileFormat.Jpeg, 1f);
You also need to add Win2D.uwp nuget package to your project.

Does CartoDB have a function to change center location based on user location?

I have a map that is integrated in my application that has data points nationwide. I would like to have the map open up at the users current location. I only see documentation for setting the center on init.
Is this even possible or should I look to Google Maps instead?
EDIT:
I have the user location(city and state) in my native app's db. I would like to use that data and pass it to the map upon init.
Yep! Try this out...
navigator.geolocation.getCurrentPosition(loadPosition);
function loadPosition(position) {
lati = position.coords.latitude;
longi = position.coords.longitude;
map = L.map('map', {zoomControl: false}).setView([lati, longi], 15);
L.tileLayer('BASE_LAYER_URL', {maxZoom: 19,}).addTo(map);
Ah just saw your edit... try setting the desired latitude and longitude as variables and then use the map.setView function (below), perhaps triggered on some user event...
map.setView(new L.LatLng(latitudeVar, longitudeVar), 19);
Which geocoder are you using? I use leaflet.js and there is a share location pop-up that appears when I open my map and zooms to the users location. I am using an esri geocoder though.

Images save to saved pics and retrieving back and displaying in my app in windows phone

Hello Friends I am New to WP7
i am working on small app now..
In that App i take one Pic from my camera and trying to save that in saved pictures with some name and i like to retrieve that Images and display again in my App Gallery screen
I am Using Pivot control for this app
in my first PivotItem Name is Gallery and second PivotItem name is Camera
Now i am working with camera fine
After taking my picture from camera i like to add some Note for that and save to my saved images and retrieving same image back and display in Gallery with Note wt i save
can any one say
how can i complete this App in good way
Code for save Images im using
mainpage.xaml.cs
private void saveimg_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
string fileName = myValue.ToShortDateString() + ".jpg";
var library = new MediaLibrary();
//library.SavePictureToCameraRoll(fileName, e.ChosenPhoto);
library.SavePicture(fileName, imageBits);
MessageBox.Show("Photo Saved to Picture Hub");
}
I need to Retrieve that that saved Image and display in my App when it loaded
If you need to access your image once it has been saved in the Media Library, you should also save it to the Isolated Storage.
Here is a tutorial that shows how to do that:
http://www.windowsphonegeek.com/tips/All-about-WP7-Isolated-Storage---Read-and-Save-Images
Save the image to Isolated Storage and Pictures Gallery. When wanting to see the image through the app, use image from Isolated Storage.
No need to use SQLite, use index numbers to save your image in Isolated storage, and also store comments with index numbers, that might ease you.

optimise performance for minesweeper-style game silverlight

I am designing a minesweeper kind of layout for a game in silverlight. Currently, I have used a square user control on the Canvas control. There are properties assigned to it.
I also want to add a functionality at a later stage. It is about curving using the bezier curves and plotting those squares on the curve with the x,y co-ordinates instead of looping through. Then I want to send the square's x,y position in an XML file.
My question is that what way should I use that will be the best optimized combination in terms of least memory consumption, fast and efficient performance as well as easy implementation.
If you experts have any other ideas, please let me know.
Thanks in advance.!
If you can draw everything as shapes and images (i.e. vector graphics) and you'll be able to take advantage of the hardware acceleration for the graphical elements. Also, you'll get better performance if you don't define your squares as UserControls, you should be creating them dynamically in code as shapes containing other shapes and then have an object model that is linked to the shapes based on their position (e.g. Dictionary squares; Dictionary squareElements).
In terms of memory consumption and file access you should keep the square's x,y position in memory as a Point strucutre and serialize to file (XML is fine) only when you need to (i.e. when the player leaves the game).
Well, over the days, I sorted out the answer myself. I continued through my Square user control and used it in the layout.
About plotting of the x/y positions, I used this:
Point point = myElement.TransformToVisual(App.Current.RootVisual as FrameworkElement)).Transform(new Point(0, 0));
There was a glitch in saving XML file because silverlight 4 does not give elevated privileges for in-browser application. But then I used this on my save button click event:
SaveFileDialog dlgSave = new SaveFileDialog();
dlgSave.DefaultExt = "xml";
dlgSave.Filter = "XML Files (XML)|*.xml;";
dlgSave.FilterIndex = 1;
strXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + myXML.ToString();//myXML is the XDocument I created globally and saved data in it
try
{
bool check = (bool)dlgSave.ShowDialog();
if (check)
{
using (Stream stream = dlgSave.OpenFile())
{
StreamWriter sw = new StreamWriter(stream, System.Text.Encoding.UTF8);
sw.Write(strXML);
sw.Close();
stream.Close();
}
MessageBox.Show("XML Saved successfully");
}
catch (SecurityException)
{
MessageBox.Show("There seems to be an issue with saving XML file on the disk, please try again...", "Something's not right", MessageBoxButton.OK);
}
catch (UnauthorizedAccessException)
{
MessageBox.Show("Saving here requires authorised permissions", "Access Denied", MessageBoxButton.OK);
}

How to find device position change using accelerometer?

I am designing a Windows Phone 7 project where I need to determine position changes of the device. I tried to use accelerometer, but it gives info on current orientation of my phone and I don't know how to convert this data to position delta. Here is some example code:
void acc_CurrentValueChanged(object sender, SensorReadingEventArgs<AccelerometerReading> e)
{
AccelerometerReading newdata = e.SensorReading;
Vector3 vect = newdata.Acceleration - data.Acceleration;
//what comes here???
}
The method above is called when accelerometer data is changed. But I don't know how to convert this data to position change of a device (i.e. I move my phone in X direction)
You can't do it.
You get position by integrating the linear acceleration twice but the error is horrible. It is useless in practice.
See the above linked answer to get some ideas what you actually can do.

Resources