I'm using Geocode Service in wp7 to get CountryName from Latitude and Longitude
I wrote following things : -
GeoCoordinate location1 = null;
private GeoCoordinateWatcher watcher;
public void FindCountryUsingGps()
{
progressbar.Visibility = Visibility.Visible;
watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.Default);
watcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(watcher_PositionChanged);
watcher.Start();
}
void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
if (watcher != null)
{
watcher.Stop();
watcher.Dispose();
watcher = null;
location1 = e.Position.Location;
ObtainCountry();//by this function you obtain country region
}
}
then added following reference :-
after that
I wrote
public void ObtainCountry()
{
if (location == null)
return;
ReverseGeocodeRequest reverseGeocodeRequest = new ReverseGeocodeRequest();
but i'm not able to write this
ReverseGeocodeRequest reverseGeocodeRequest = new ReverseGeocodeRequest();
line , it's comes as red
in wp7 , what's this?
Try removing/re-adding the service reference. Sometimes I've had issues where the code didn't get generated properly. The code should be under the ServiceReference folder, in a code file called Reference.cs.
Related
I'm trying to fetch my location using GeoClue and GWeather.
I want to display the name of my city in the blank space.
public class Epoch.LabelsGrid : Gtk.Grid {
public Gtk.Label face1_label;
public Gtk.Label face2_label;
public Gtk.Label face3_label;
public Gtk.Label face4_label;
public GClue.Location? geo_location {get; private set; default = null;}
public GWeather.Location location;
private GClue.Simple simple;
construct {
face1_label = new Gtk.Label ("");
face1_label.label = dgettext ("libgweather-locations", location.get_city_name ());
face1_label.halign = Gtk.Align.CENTER;
face1_label.hexpand = true;
face1_label.margin_top = 6;
face1_label.set_ellipsize (END);
face1_label.set_max_width_chars (12);
face2_label = new Gtk.Label ("Paris");
face2_label.set_markup ("<span font_desc='Inter 14'><b>Paris</b></span>");
face2_label.halign = Gtk.Align.CENTER;
face2_label.hexpand = true;
face2_label.margin_top = 6;
face2_label.set_ellipsize (END);
face2_label.set_max_width_chars (12);
face3_label = new Gtk.Label ("London");
face3_label.set_markup ("<span font_desc='Inter 14'><b>London</b></span>");
face3_label.halign = Gtk.Align.CENTER;
face3_label.hexpand = true;
face3_label.margin_top = 6;
face3_label.set_ellipsize (END);
face3_label.set_max_width_chars (12);
face4_label = new Gtk.Label ("New York");
face4_label.set_markup ("<span font_desc='Inter 14'><b>New York</b></span>");
face4_label.halign = Gtk.Align.CENTER;
face4_label.hexpand = true;
face4_label.margin_top = 6;
face4_label.set_ellipsize (END);
face4_label.set_max_width_chars (12);
}
public async void seek () {
try {
simple = yield new GClue.Simple ("com.gihhub.Suzie97.epoch", GClue.AccuracyLevel.CITY, null);
} catch (Error e) {
warning ("Failed to connect to GeoClue2 service: %s", e.message);
return;
}
simple.notify["location"].connect (() => {
on_location_updated.begin ();
});
on_location_updated.begin ();
}
public async void on_location_updated () {
geo_location = simple.get_location ();
location = location.find_nearest_city (geo_location.latitude, geo_location.longitude);
}
}
This is the code.
The code compiles but while executing the program, (com.github.Suzie97.epoch:30386): GWeather-CRITICAL **: 13:21:03.758: gweather_location_get_city_name: assertion 'loc != NULL' failed this warning is displayed.
I found this code snippet on an app by Daniel Fore called Nimbus (Link to nimbus repo)
public void on_location_updated (double latitude, double longitude) {
location = GWeather.Location.get_world ();
location = location.find_nearest_city (latitude, longitude);
if (location != null) {
weather_info.location = location;
weather_info.update ();
stack.visible_child_name = "weather";
}
}
Do I need to do something similar to this?
According to the error message, gweather_location_get_city_name () is emitting an error because the location is NULL (loc != NULL is false). Look at where you're calling get_city_name (). It's at the very top of your constructor, before location is set to anything. You need to wait until you have a location before you try to use it.
Then you should use something like the Nimbus code. It handles the case when simple.get_location () returns NULL (if it can't find your location), and also initializes the GWeather location so it can call find_nearest_city ().
SaveFileDialog in XamarinForms
My requirement is to save a file in Xamarin.Forms like below image and what ever I tried so far is:
public class CustomWebViewRenderer : WebViewRenderer
{
protected override void OnElementChanged (ElementChangedEventArgs<WebView> e)
{
base.OnElementChanged (e);
if (e.NewElement != null)
{
var customWebView = Element as CustomWebView;
Control.Settings.AllowUniversalAccessFromFileURLs = true;
string root = Android.OS.Environment.ExternalStorageDirectory.ToString();
// Java.IO.File myDir = new Java.IO.File(root + "/WingsPdfs");
// myDir.Mkdir();
string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
Java.IO.File file = new Java.IO.File(path, "WingsPdfGenerated.pdf");
FileOutputStream outs = new FileOutputStream(file);
outs.Write(customWebView.PdfStream.ToArray());
outs.Flush();
outs.Close();
try
{
Control.LoadUrl(string.Format("file:///android_asset/pdfjs/web/viewer.html?file={0}", file));
}
catch(Exception ex)
{
}
}
}
}
In the above code I hardcoded the location of the file but I want user to select particular location and save to the selected location.
Thank You
enter image description here
I am developing a Windows Phone app in which I have to post a photo to facebook. And that particular photo is choosen by using PhotoChooserTask or CameraChooserTask.
Normally, I can post a particular photo successfully, but I am facing problem to post the selected photo. I saw some link like
link
So please if anyone know about the issue please help me out.
Thanx in advance.
EDIT
private void PostClicked(object sender, RoutedEventArgs e)
{
//Client Parameters
var parameters = new Dictionary<string, object>();
//var parameters1 = new Dictionary<>();
parameters["client_id"] = FBApi;
parameters["redirect_uri"] = "https://www.facebook.com/connect/login_success.html";
parameters["response_type"] = "token";
parameters["display"] = "touch";
parameters["ContentType"] = "image/png";
//The scope is what give us the access to the users data, in this case
//we just want to publish on his wall
parameters["scope"] = "publish_stream";
Browser.Visibility = System.Windows.Visibility.Visible;
Browser.Navigate(client.GetLoginUrl(parameters));
}
private void BrowserNavitaged(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
FacebookOAuthResult oauthResult;
//Making sure that the url actually has the access token
if (!client.TryParseOAuthCallbackUrl(e.Uri, out oauthResult))
{
return;
}
//Checking that the user successfully accepted our app, otherwise just show the error
if (oauthResult.IsSuccess)
{
//Process result
client.AccessToken = oauthResult.AccessToken;
//Hide the browser
Browser.Visibility = System.Windows.Visibility.Collapsed;
PostToWall();
}
else
{
//Process Error
MessageBox.Show(oauthResult.ErrorDescription);
Browser.Visibility = System.Windows.Visibility.Collapsed;
}
}
private void PostToWall()
{
string imageName = "ic_launcher.png";
StreamResourceInfo sri = null;
Uri jpegUri = new Uri(imageName, UriKind.Relative);
sri = Application.GetResourceStream(jpegUri);
try
{
byte[] imageData = new byte[sri.Stream.Length];
sri.Stream.Read(imageData, 0, System.Convert.ToInt32(sri.Stream.Length));
FacebookMediaObject fbUpload = new FacebookMediaObject
{
FileName = imageName,
ContentType = "image/jpg"
};
fbUpload.SetValue(imageData);
string name1 = eventname.Text;
string format = "yyyy-MM-dd";
string message1 = eventmessage.Text;
string date1 = datepicker.ValueString;
DateTime datevalue = DateTime.Parse(date1);
string d = datevalue.ToString(format);
string memoType = "Tribute";
var parameters = new Dictionary<string, object>();
var parameters1 = new Dictionary<string, object>();
parameters["message"] = name1 + "\n" + d + "\n" + memoType + "\n" + message1;
parameters["source"] = fbUpload;
webservice();
client.PostTaskAsync("me/photos", parameters);
}
catch (Exception error)
{
MessageBox.Show(error.ToString());
}
//client.PostTaskAsync("me/photos", parameters1);
}
On clicking on a button I am calling PostClicked class and it will directly go to facebook mainpage and it will ask for login information. Like this I am doing.
Please check it out
Now I can share a photo to facebook successfully by using photochoosertask or cameratask.
I am sharing my experience so that if anyone face the same issue can use it.
private void photoChooserTask_Completed(object sender, PhotoResult e)
{
BitmapImage image = new BitmapImage();
image.SetSource(e.ChosenPhoto);
SaveImageToIsolatedStorage(image, tempJPEG);
this.image.Source = image;
}
public void SaveImageToIsolatedStorage(BitmapImage image, string fileName)
{
using (var isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
if (isolatedStorage.FileExists(fileName))
isolatedStorage.DeleteFile(fileName);
var fileStream = isolatedStorage.CreateFile(fileName);
if (image != null)
{
var wb = new WriteableBitmap(image);
wb.SaveJpeg(fileStream, wb.PixelWidth, wb.PixelHeight, 0, 100);
}
fileStream.Close();
}
}
With this you can able to save the selected image to IsolatedStorage.
And then at the time of posting the photo to facebook you have to select the image from IsolatedStorage.
private void PostClicked(object sender, RoutedEventArgs e)
{
//Client Parameters
var parameters = new Dictionary<string, object>();
parameters["client_id"] = FBApi;
parameters["redirect_uri"] = "https://www.facebook.com/connect/login_success.html";
parameters["response_type"] = "token";
parameters["display"] = "touch";
//The scope is what give us the access to the users data, in this case
//we just want to publish on his wall
parameters["scope"] = "publish_stream";
Browser.Visibility = System.Windows.Visibility.Visible;
Browser.Navigate(client.GetLoginUrl(parameters));
}
private void BrowserNavitaged(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
FacebookOAuthResult oauthResult;
//Making sure that the url actually has the access token
if (!client.TryParseOAuthCallbackUrl(e.Uri, out oauthResult))
{
return;
}
//Checking that the user successfully accepted our app, otherwise just show the error
if (oauthResult.IsSuccess)
{
//Process result
client.AccessToken = oauthResult.AccessToken;
//Hide the browser
Browser.Visibility = System.Windows.Visibility.Collapsed;
PostToWall();
}
else
{
//Process Error
MessageBox.Show(oauthResult.ErrorDescription);
Browser.Visibility = System.Windows.Visibility.Collapsed;
}
}
private void PostToWall()
{
try
{
byte[] data;
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile(tempJPEG, FileMode.Open, FileAccess.Read))
{
data = new byte[fileStream.Length];
fileStream.Read(data, 0, data.Length);
fileStream.Close();
}
}
//MemoryStream ms = new MemoryStream(data);
//BitmapImage bi = new BitmapImage();
//// Set bitmap source to memory stream
//bi.SetSource(ms);
//this.imageTribute.Source = bi;
FacebookMediaObject fbUpload = new FacebookMediaObject
{
FileName = tempJPEG,
ContentType = "image/jpg"
};
fbUpload.SetValue(data);
string name1 = eventname.Text;
string format = "yyyy-MM-dd";
string message1 = eventmessage.Text;
string date1 = datepicker.ValueString;
DateTime datevalue = DateTime.Parse(date1);
string d = datevalue.ToString(format);
string memoType = "Notice";
var parameters = new Dictionary<string, object>();
var parameters1 = new Dictionary<string, object>();
parameters["message"] = name1;
parameters["source"] = fbUpload;
webservice();
client.PostTaskAsync("me/photos", parameters);
}
catch (Exception error)
{
MessageBox.Show(error.ToString());
}
}
Thanx to all....
you can do that by two methods :
1) by using mediasharetask in which it will show u all sharing account to which your phone is synced like facebook,gmail,linkdin,twitter,etc : it can be used like like this.
ShareMediaTask shareMediaTask = new ShareMediaTask();
shareMediaTask.FilePath = path;
shareMediaTask.Show();
2) by using facebook sdk. you can get the package from nuget manager and then u can use it to share on facebook.
I hope this might help u.
I developed a navigation application for windows phone 7.1. It was running fine there. After updating to 8.0 my GeoCoordinateWatcher isnt working anymore. I know that I could use Geolocator instead, but I refuse to do so, because of lack of time.
For my app I read the current position of my watcher to store it for an object instance with location information. When I save my object instance the longitude and latitude are 0.0. Even when I change the position in my emulator still 0.0. The same issue occurs on my other pages, which use GeoCoordinateWatcher. It doesnt work. As I already said, on WP 7.1 - 7.8 it works very well.
public Map()
{
InitializeComponent();
watcher = new GeoCoordinateWatcher();
watcher.MovementThreshold = 20;
watcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(watcher_StatusChanged);
watcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(watcher_PositionChanged);
}
void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
if (e.Position.Location.IsUnknown)
{
MessageBox.Show("Please wait while your prosition is determined.");
return;
}
geo.Latitude = e.Position.Location.Latitude;
geo.Longitude = e.Position.Location.Longitude;
}
try this code:
GeoCoordinateWatcher watch;
public GeoCoordinate loc = null;
public MainPage()
{
InitializeComponent();
if (watch == null)
{
watch = new GeoCoordinateWatcher(GeoPositionAccuracy.High)
{
MovementThreshold=10
};
watch.Start();
watch.PositionChanged += watch_PositionChanged;
}
}
void watch_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
//throw new NotImplementedException();
Dispatcher.BeginInvoke(()=>LocUpdate(e));
}
void LocUpdate(GeoPositionChangedEventArgs<GeoCoordinate> e)
{
try
{
location = new GeoCoordinate(e.Position.Location.Latitude, e.Position.Location.Longitude);
}
catch
{
MessageBox.Show("Error");
}
}
I need to update the userlocation to server when the location is changed .Please tell me how to acheive this?
using below method:
void GeoPositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
_pushpins.Clear();
var cor = new GeoCoordinate(e.Position.Location.Latitude, e.Position.Location.Longitude);
//Using the current coordinates define the Map center to those coordinates.
map.Center = cor;
_pushpins.Add(new PushpinModel
{
UserId=userId,
Description = "test",
Name = "test",
Location = new GeoCoordinate(e.Position.Location.Latitude,
e.Position.Location.Longitude),
DatetimeAdded = DateTime.Now
});
map.ZoomLevel = 15;
//locationupdate method
locationupdate(e.Position.Location.Latitude,
e.Position.Location.Longitude);
}
private void locationupdate(double lat,double lon)
{
bool isAvailable = NetworkInterface.GetIsNetworkAvailable();
if (isAvailable == true)
{
try
{
WebClient wc = new WebClient();
wc.DownloadStringAsync(
new Uri("http://{ipaddress}/Network/Records/UpdateLocation?userid="+userId+"&latitude="+lat+"&longitude="+lon));
wc.DownloadStringCompleted +=
new DownloadStringCompletedEventHandler(
wc_DownloadStringUpdateCompleted);
}
catch (Exception ex)
{
throw;
}
}
else
{
MessageBox.Show("Network is not available.Please try again later");
}
}
Please tell me the above will update the location whenever user was changed his location?
Separate your goal...
Do you already know how to get the user location?
Use background agents to run taks on the background (if necessary) http://www.silverlightshow.net/items/Windows-Phone-7.5-Use-Background-agents.aspx
Create a webservice to update you're server