Web Core & GetGeocodingSync

Hi,

How do I use GetGeocodingSync in Web Core? Can't find any documentation.

Thanks,

Ken

Further Clarification. Using GetGeocoding via the Google service returns address information such as Street and Location but GetGeocodingSync only returns the coordinates. How can I get the address details?

If you want to have an address based on a geo coordinate, this process is called reverse geocoding.

This is also covered in TMS FNC Maps
See:

Thanks but I don't understand. All I have is the postcode. I don't understand why GetGeocoding returns the address details as well as the coordinates but GetGeocodingSync does not?

Your original question

"How can I get the address details?"

Now, you claim you have a post code?

To what component refers GetGeocoding & GetGeocodingSync? There is no such component in TMS WEB Core with these methods.

Please provide full detailed instructions to what you want and what you use.

function GetAddressData(const postcode:String):JSValue;
var
  Geo:TTMSFNCGeocoding;
  Rec:TTMSFNCMapsCoordinateRec;
  Res:JSValue;
begin
  Geo:=TTMSFNCGeocoding.Create(Nil);
  Geo.Service:=gsGoogle;
  Geo.APIKey:='whatever';
  Rec:=Await(Geo.GetGeocodingSync(lookup));
  console.log(Rec);
  Geo.Free;;
end;

This belongs under

Hi,

This behavior is by design.

Full address details are with the asynchronous calls GetGeocoding and GetReverseGeocoding in the associated event.

The synchronous calls only return a single value (coordinates for GetGeocoding and address string for GetReverseGeocoding).

Then I question the design! I guess I'll just use the Google API directly then!

Thank you for your feedback.
We'll consider adding a sync call that returns the full address details in a future version of TMS FNC Maps.

Thanks. In the meantime this seems to give me what I want:

function GetAddressData(const lookup:String):JSValue;
var
  Res:JSValue;
begin
  asm
    var Res = {street:"",district:"",town:"",county:"",lat:0,lng:0};
    let url = "https://maps.googleapis.com/maps/api/geocode/json?address=" + lookup + "&key="+
      pas.ResourceStrings.googleMapsAPIKey;
    const resp = await axios.get(url);
    if (resp.status) {
      let add = resp.data.results[0].address_components;
      for (let i = 0; i < add.length; i++) {
        switch(add[i].types[0]) {
          case "sublocality":
            Res.district = add[i].long_name;
            break;
          case "postal_town":
            Res.town = add[i].long_name;
            break;
          case "route":
            Res.street = add[i].long_name;
            break;
          case "administrative_area_level_2":
            Res.county = add[i].long_name;
            break;
        }
      }
      Res.lat = resp.data.results[0].geometry.location.lat;
      Res.lng = resp.data.results[0].geometry.location.lng;
    }
  end;
  Result:=Res;
end;