Solution 1 :
Looks like the problem is how you are trying to access your json. I’m not sure(because it doesn’t say) as to where are you storing it, but here the docs explain a smooth explanation as to how access stored files in a mobile phone using Xamarin Forms
Solution 2 :
You want to read from ‘DATA.json’ but gave the path ‘File.json’.
Problem :
I am trying here to consume the data from a JSON file:
DATA.json
[
{"Label"
:"USA",
"Adress":"This is the us",
"Lat":"36.9628066",
"Lng":"-122.0194722"
},
{ "Label" :"USA",
"Address":"2020",
"Lat":"36.9628066",
"Lng":"-122.0194722" }
]
Then applying it in my Mainclass
:
using System.Collections.Generic;
using Xamarin.Forms.Maps;
using Xamarin.Forms;
using System.IO;
using Newtonsoft.Json;
using System;
namespace Orbage
{
class MapPage : ContentPage
{
public MapPage()
{
CustomMap customMap = new CustomMap
{
MapType = MapType.Street
};
// ...
Content = customMap;
var json = File.ReadAllText("File.json");
var places = JsonConvert.DeserializeObject<List<File>>(json);
foreach (var place in places)
{
CustomPin pin = new CustomPin
{
Type = PinType.Place,
Position = new Position(Double.Parse(place.Lat), Double.Parse(place.Lng)),
Label = place.Label,
Address = place.Address,
Name = "Xamarin",
Url = "http://xamarin.com/about/"
};
customMap.CustomPins = new List<CustomPin> { pin };
customMap.Pins.Add(pin);
customMap.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(37.79752, -122.40183), Distance.FromMiles(1.0)));
}
}
}
}
But when I put the file in there it says that it doesn’t exist.
Error:
FilenotfoundException
Whats the fix for this.
I tried:
- Changing the location of the file.
- Its name
= Instead of E:/-/- I even wrotefile.json
but I still get the same error.
Comments
Comment posted by ItsRaptorman
Please help me!
Comment posted by ItsRaptorman
@Jason the error is not coming now but the marker isn’t showing
Comment posted by Jason
changing the question you asked completely invalidates the answer that I gave you. Please don’t do that.
Comment posted by ItsRaptorman
oops sorry I din’t know that….. Please retype the answer and add this line MainPage = new Orbage.MapPage(); Because that was the fix and the using forms.
Comment posted by Jason
where is your custom renderer?
Comment posted by ItsRaptorman
Thanks for answering.
Comment posted by ItsRaptorman
No, That was only for the answerer to understand what I wrote there.. Thanks for writing the answer!