This commit is contained in:
zpc 2025-08-07 20:35:31 +08:00
parent f454ae0417
commit f695fbbdc6
7 changed files with 10 additions and 7 deletions

View File

@ -170,7 +170,7 @@ namespace ZR.Admin.WebApi.Controllers
var (result, message) = resultTuple.Value;
if (result != null)
{
geocodedAddress = result.Regeocode.Formatted_Address;
geocodedAddress = result;
}
regeo = message ?? "";
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

View File

@ -20,7 +20,7 @@ public class GeoCodeService
_httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient));
}
public async Task<(ReGeoCodeResult, string)?> GetReGeoCodeAsync(string location, string coordsys = "gcj02")
public async Task<(string, string)?> GetReGeoCodeAsync(string location, string coordsys = "gcj02")
{
if (string.IsNullOrWhiteSpace(location))
{
@ -33,19 +33,22 @@ public class GeoCodeService
{
var response = await _httpClient.GetAsync(requestUrl);
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
var json = JsonDocument.Parse(content);
var result = JsonConvert.DeserializeObject<ReGeoCodeResult>(content);
return new(result, content);
// 直接提取 formatted_address
var j = json.RootElement
.GetProperty("regeocode")
.GetProperty("formatted_address")
.GetString();
return new(j, content);
}
catch (HttpRequestException ex)
{
//throw new ApplicationException("Error calling AMap API", ex);
}
return new(null, "");
return new("", "");
}
}
/// <summary>