dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.97k stars 1.72k forks source link

There is a missing value in the return value of the GetPlacemarksAsync method. #13572

Open cat0363 opened 1 year ago

cat0363 commented 1 year ago

Discussed in https://github.com/dotnet/maui/discussions/13449

As noted in the Discussions, the return value of the GetPlacemarksAsync method has missing values. Therefore, the information stored in the Placemarks object cannot be used to reconstruct the correct address. I would like a method for reverse geocoding as an address (string) from latitude and longitude provided in Xamarin.Forms also in .NET MAUI.

Xamarin.Forms provided the following methods:

public static async Task<IEnumerable<string>> GetAddressesForPositionAsync(Position position)

In .NET MAUI, latitude and longitude are now stored in the Location object, so I expect the following methods to be provided.

public static async Task<IEnumerable<string>> GetAddressesForLocationAsync(Location location)

As a workaround for this problem, by implementing the following method as a service, we are trying to get the same result as the method provided by Xamarin.Forms.

[Android]

public partial async Task<IEnumerable<string>> GetAddressesForLocationAsync(Location position)
{
  var geocoder = new AGeocoder(MainActivity.Context);
  var addresses = await geocoder.GetFromLocationAsync(position.Latitude, position.Longitude, 5);
  return addresses.Select(p =>
  {
    var lines = Enumerable.Range(0, p.MaxAddressLineIndex + 1).Select(p.GetAddressLine);
    return string.Join("\n", lines);
  });
}

[iOS]

public partial Task<IEnumerable<string>> GetAddressesForLocationAsync(Location position)
{
  var location = new CLLocation(position.Latitude, position.Longitude);
  var geocoder = new CLGeocoder();
  var source = new TaskCompletionSource<IEnumerable<string>>();
  geocoder.ReverseGeocodeLocation(location, (placemarks, error) =>
  {
    if (placemarks == null)
      placemarks = new CLPlacemark[0];
    IEnumerable<string> addresses = placemarks.Select(p => ABAddressFormatting.ToString(p.AddressDictionary, false));
    source.SetResult(addresses);
  });
  return source.Task;
}

I have implemented these methods in a way as described on the site below. https://www.davidbritch.com/2021/11/invoke-platform-code-in-net-maui.html

Is it possible to provide the method described in this problem for .NET MAUI as well? I'm hoping the above method is provided because the correct address cannot be reconstructed from the Placemark object. At least the address I got as a string is not missing.

Originally posted by **cat0363** February 20, 2023 In Xamarin.Forms, you could get the address as a string from the latitude and longitude using the reverse geocoding API, but .NET MAUI can no longer do that. Instead, the information that makes up the address is decomposed and stored in the Placemark object. Even if you reconstruct the address based on the information in this Placemark object, you will not get the same address as in Xamarin.Forms. The information stored in the Placemark object is missing the information that makes up the address. I live in Japan, and at least in Japan, the Placemark object doesn't store the correct information that makes up the address. I would like you to provide the following method to get the address provided in Xamarin.Forms as a string. **public static async Task> GetAddressesForPositionAsync(Position position)** or **public static async Task> GetAddressesForLocationAsync(Location location)** It is possible to port the Xamarin.Forms source code to .NET MAUI, but I would like .NET MAUI to provide it as standard. For example, if the Android emulator's GPS location information is set as follows: ![image](https://user-images.githubusercontent.com/125236133/220290399-fa860bf6-473a-4769-bef3-51af780c3d23.png) Although the address is 1 Chome-4 Yaesu, Chuo City, Tokyo 103-0028, Japan the result obtained by calling the GetPlacemarksAsync method is as follows. ![image](https://user-images.githubusercontent.com/125236133/220290656-46b031d8-5253-47e6-8320-277e5399b0fd.png) The address stored in the Placemark object is 1 Chome-4, Chuo City, Tokyo 103-0028, Japan not 1 Chome-4 **Yaesu**, Chuo City, Tokyo 103-0028, Japan. The correct address cannot be obtained from the information stored in the Placemark object. I want to get the address as a string, not as a Placemark object. I am sorry to bother you when you are busy, but I would appreciate your consideration.
ghost commented 1 year ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

cat0363 commented 1 year ago

I have uploaded a workaround for this issue below. I hope this helps someone who is having the same problem. https://github.com/cat0363/Maui-Workaround13572

Annotation: Please change "YOUR API KEY" in AndroidManifest.xml to the API KEY you are using before executing.

<meta-data android:name="com.google.android.geo.API_KEY" android:value="YOUR API KEY" />

The methods that existed in Xamarin.Forms are essential because the app we are developing needs to obtain the address from the location information. I hope that this issue will be taken up at the milestone planning meeting.