How to Obtain The User Address By Knowing their Longitude and Latitude - android-location

I am using LocationManager in android application to obtain the user current coordinates. It works fine for me but the second step I want to display the formatted address to the user instead of displaying it in logn and lat format.
can you pleeease help me ?

try this:
Geocoder geocoder = new Geocoder(context);
List<Address> address = geocoder.getFromLocation(Latitude, Longitude, 1);

Related

How to read Geo Coordinates From Image Property using Xamarin Forms?

I have an image with longitude and latitude coordinates, can any one tell me how do i get it? I have tried
if (CrossMedia.Current.IsPickPhotoSupported)
{
MediaFile photoPicked = await CrossMedia.Current.PickPhotoAsync();
if (photoPicked != null)
{
//await DisplayAlert("Photo Location", photoPicked.Path, "OK");
//path = photoPicked.Path;
using (Stream streamPic = photoPicked.GetStream())
{
var picInfo = ExifReader.ReadJpeg(streamPic);
ExifOrientation orientation = picInfo.Orientation;
//MainImage123.Source = ImageSource.FromStream(() => photoPicked.GetStream());
latitude = picInfo.GpsLatitude;
longitude = picInfo.GpsLongitude;
var filepath = photoPicked.AlbumPath;
var filepath1 = photoPicked.Path;
}
}
}
It works when I picked photo and trying to get its coordinates, but I have to take multiple photos from image gallery and find its coordinates.
does any one know how to read image geo coordinates? please help me.
You can use the ExifLib.PCL Nuget Package to read an image metada, by viewing your "code sample", i think you are using the Plugin.Media to take images/get images from the galery, be sure to use SaveMetaData = true when taking an photo from your app.
Once you have set the SaveMetaData to true, use the ExifLib to obtain the MetaData like this:
MediaFile photo;
using (Stream streamPic = photo.GetStream())
{
var picInfo = ExifReader.ReadJpeg(streamPic);
double lat = picInfo.GpsLatitude;
double lon = picInfo.GpsLongitude;
}
Also, as a plus, you have even more info on the photo (date taken, author, size, etc.).
UPDATE:
After Reading it again, it seems that the problem is that you are not able to pick multiple images from the galery, and NOT being able to get the lat and lon from the photos. At the moment, Plugin.Media doesn't support multi-picking.
Your question was unclear however - I think you are trying to make it work with multiple images together. How you can be able to pick multiple images together?
The plugin "CrossMedia" doesn't support picking up multiple images.
Your solution requires a lot of work to be done to be able to Pickup multiple images at once. So Follow this nice step-by-step tutorial here:
https://xamgirl.com/select-multiple-images-from-gallery-in-xamarin-forms/
With above you will be able to get all the images you need at once.
After you get List, all you have to do is to loop through those images and call your existing code.

Speed not updating when using GeoCoordinateWatcher

When using the GeoCoordinateWatcher class to get updated GPS position and speed inside my Windows Phone application, the latitude and longitude updates, but the speed remains at a constant value: 5.95 (as well as the course).
I initialize the Geo Watcher with the following code:
GeoCoordinateWatcher GeoWatcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
And start the listening process using the snipped:
GeoWatcher.StatusChanged += GeoWatcherStatusChanged;
GeoWatcher.PositionChanged += OnGeoWatcherPositionChanged;
GeoWatcher.MovementThreshold = 0.5;
GeoWatcher.Start();
And finally, the method OnGeoWatcherPositionChanged contains the following code:
textSpeed.Text = args.Position.Location.Speed.ToString();
Where textSpeed is a simple TextBox.
Does anyone know why Speed remains at a constant value? Thanks in advance.

Get the longitude and latitude by providing the locality address in windows phone 7

I want to get the geolocation by providing the locality address in windows phone app development.??//
First Of all take a text block to save and see Coordinates .
Now Name It as txtBlock1 .
Now you can add the following Code in Map Hold event .
The point where you hold the mouse . it will show you the coordinates both longitude and lattitude.
And you can use them as a string or as a location wise any where
mapMain.Hold += (s, e) =>
{
Point p = e.GetPosition(this.mapMain);
GeoCoordinate geo = new GeoCoordinate();
geo = mapMain.ViewportPointToLocation(p);
txtBlock1.text = geo.ToString();
};
Hope It helps... :-)
Use the Bing Maps Geocode Service

How to Get the the Current city name using gps in bing map

I have used bing map in my app,where i locate the current location using gps and i'm getting the co-ordinates using geoco-ordinatewatcher as well and pin the current location with pushpin. but my issue is that i wanna get the current city and country name where the pushpin is pointing. i couldn't get that using map.center property. can anyone help me out.. Thanks in advance...
The following blog post should assist you :-
http://www.nickharris.net/2010/12/how-to-reverse-geocode-a-location-to-an-address-on-windows-phone-7/
Unfortunately, the CivicAddressResolver is currently not implemented on Windows Phone so you would have to use an online based solution.
please, refer the below code
ReverseGeocodeRequest reverseGeocodeRequest = new ReverseGeocodeRequest();
// Set the credentials using a valid Bing Maps key
reverseGeocodeRequest.Credentials = new GeoCodeService.Credentials();
reverseGeocodeRequest.Credentials.ApplicationId = "Your bing map key";
// Set the point to use to find a matching address
GeoCodeService.Location point = new GeoCodeService.Location();
point.Latitude = Your lat;
point.Longitude = Your lng;
reverseGeocodeRequest.Location = point;
// Make the reverse geocode request
GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
geocodeService.ReverseGeocodeCompleted += new EventHandler<ReverseGeocodeCompletedEventArgs>(geocodeService_ReverseGeocodeCompleted);
geocodeService.ReverseGeocodeAsync(reverseGeocodeRequest);
void geocodeService_ReverseGeocodeCompleted(object sender, ReverseGeocodeCompletedEventArgse)
{
string text1;
GeocodeResponse geocodeResponse = e.Result;
System.Diagnostics.Debug.WriteLine("GeoCode Response is :"+geocodeResponse);
if (geocodeResponse.Results.Count() > 0)
text1 = geocodeResponse.Results[0].DisplayName;
else
text1 = "No Results found";
textBlock1.Text = text1;
System.Diagnostics.Debug.WriteLine("Location is :"+text1);
}
There is no way to resolve a location from lat/long coordinates on the device.
To do so would require that a database of all places ship with the device to do the lookup. Such a database would be huge and present issues with keeping it updated.

Windows Phone 7 GetDistanceTo() returns incorrect distance

I am developing a small Windows Phone application. I am storing the current location of user in the database.
Here is the code to retrieve the current location which is stored in database.
public void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
CurrentLatitude = e.Position.Location.Latitude.ToString();
CurrentLongitude = e.Position.Location.Longitude.ToString();
}
We need to allow user to do some activity if he is under the 400 meters from his saved location.
I am using the following code to calculate the distance.
internal double GetDistanceTo(GeoCoordinate ClientLocation)
{
double distanceInMeter;
GeoCoordinate currentLocation = new GeoCoordinate(Convert.ToDouble(watcher.Position.Location.Latitude.ToString()), Convert.ToDouble(watcher.Position.Location.Longitude.ToString()));
distanceInMeter = currentLocation.GetDistanceTo(ClientLocation);
return distanceInMeter;
}
ClientLocation : is the location saved in the database.
So my problem is that it gives extremly large distance even the user is standing at the same location(under 1 meter) which is saved in the database.
Example cordinates (extracted from device)
Saved in Database
Lat : 29.8752546310425
Long: 73.8865985870361
Current Cordinates
Lat : 29.8734102249146
Long :73.9049253463745
Distance
1780.45
Could anybody suggest me what is wrong here or a better way to get the distance between two coordinates?
According to boulter.com it is 1.11miles from A to B. Thats about 1780m, so I dont see what the problem is. Have a read of the Moveable Type help on lat and long calculations.

Resources