Radzen Google Map Address Lookup

Radzen Team,

Does the map support address lookup. I need to put businesses on a map however I do not have the business latitude and longitudes I have their addresses, does the map support this behavior or will it in the near future?

You need to subscribe to another google service to do this. You can find it on line but essentially it’s another free service you get from the same place as you got the google maps API. Unfortunately I can’t remember what’s it’s called. If you can’t find it let me know and I’ll have another look.

John

Its Google geocode service. I've used it before, just wondering if the functionality was built into the radzen control

Not as far as I know. I just wrote a method to ue it to get the coordinates.

1 Like

Hi @johnmu
Do you think there is a way to integrate Google address lookup in Radzen? I would like to use the lookup rather than have users type in the address. I manage to implement it in a Lightswitch application and I would love to find a way to do it in Radzen. Any help with this would be appreciated. Thanks.

Dominic,

I have a method that takes the postcode which the user provides and then it queries google to get the map coordinates. If that’s what you mean I’ll post the code.

John

Hi @johnmu,
Yes please :grin: that would be very helpful as it would give me an insight on how to query a Google API from Radzen. The feature I am looking to implement is the " Autocomplete for Addresses and Search Terms" from Google https://developers.google.com/maps/documentation/javascript/places-autocomplete

1 Like

Dominic,

here's my code

protected async System.Threading.Tasks.Task Button0Click(MouseEventArgs args)
        {
            if (PostCode!=null)
            {
                var getCoordsAsyncResult = await GetCoordsAsync($"{PostCode}");
            }
        }

then I put this in a partial page class

 public async Task<Tuple<double, double>> GetCoordsAsync(string postcode)
        {
            string url = string.Format("https://maps.google.com/maps/api/geocode/xml?key={1}&address={0}&sensor=false", Uri.EscapeDataString(postcode), Globals.GoogleMapsAPI);

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            Stream receiveStream = response.GetResponseStream();
            Encoding encode = System.Text.Encoding.GetEncoding("utf-8");

            StreamReader readstream = new StreamReader(receiveStream, encode);

            DataSet dsResult = new DataSet();

            dsResult.ReadXml(readstream);

            response.Close();
            readstream.Close();

            Tuple<double, double> output=new Tuple<double, double>(0,0);

            DataTable dt = new DataTable();

            foreach (DataRow row in dsResult.Tables["result"].Rows)
            {
                string geometry_id = dsResult.Tables["geometry"].Select("result_id = " + row["result_id"].ToString())[0]["geometry_id"].ToString();

                DataRow location = dsResult.Tables["location"].Select("geometry_id=" + geometry_id)[0];

               output = Tuple.Create(Convert.ToDouble(location["lat"]), Convert.ToDouble(location["lng"]));

            };

            await AddMarkerfromPostCode(output.Item1, output.Item2);

            return output;

        }

I'm sure there are better tighter ways to write this but it works.

2 Likes

You can format your code by nesting it inside ``` (triple backtick) blocks. For example:


```
code
```

thanks, didn't know that

I am going to work on an example for this. more to come.

An example of using Google Places Autocomplete with Blazor Radzen components.
See example code: https://github.com/MSIH/Blazor-Radzen-Google-Places-Autocomplete

See Demo site: https://blazorradzengoogleplacesautocomplete.azurewebsites.net/

3 Likes

Great example. However if you attempt to use this on a Raden Dialog it will not work Zipped Example Here