Topic: FindLocationNameExample and OnlineMapsGoogleGeocodingResult

In this example you have a string as the argument for OnQueryComplete. I've tried changing it to use an OnlineMapsGoogleGeocodingResult instead, but it tells me "No overload for 'OnQueryComplete' matches delegate 'Action<string>'".


        private void OnMapClick()
        {
            // Get the coordinates where the user clicked.
            Vector2 mouseCoords = OnlineMapsControlBase.instance.GetCoords();

            // Try find location name by coordinates.
            OnlineMapsGoogleGeocoding query = OnlineMapsGoogleGeocoding.Find(null, mouseCoords.y + "," + mouseCoords.x);
            query.OnComplete += OnQueryComplete;
        }

        private void OnQueryComplete(OnlineMapsGoogleGeocodingResult s)
        {
            // Show response in console.
            Debug.Log(s.formatted_address);
        }

How can I get access to the OnlineMapsGoogleGeocodingResult in OnQueryComplete so I have easier access to its members and such?

Thanks!

Re: FindLocationNameExample and OnlineMapsGoogleGeocodingResult

Something like that:

private void OnQueryComplete(string s)
{
    OnlineMapsGoogleGeocodingResult[] results = OnlineMapsGoogleGeocoding.GetResults(s);
    // Show response in console.
    foreach (OnlineMapsGoogleGeocodingResult result in results)
    {
        Debug.Log(result.formatted_address);
    }
}
Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: FindLocationNameExample and OnlineMapsGoogleGeocodingResult

Perfect, thanks! smile

Re: FindLocationNameExample and OnlineMapsGoogleGeocodingResult

Looking at the results that gives me, I wonder is there a way to get more information about it? Right now it's giving me the street address, the city, state, etc. But if I click on a golf course, I'd love to get that information, or a hospital or what have you. Is that information in the geocoding result, or do I need to do a different call to OSM or something?

Thanks!

Re: FindLocationNameExample and OnlineMapsGoogleGeocodingResult

Looks like I need to break further into the results data type. I'll see if that does what I need.

Thanks!

Re: FindLocationNameExample and OnlineMapsGoogleGeocodingResult

I was hoping the location_type or types properties might have that info, but they don't seem to. Only things like "APPROXIMATE" and "political" etc. Any way to know if I just clicked on a hospital or a tennis court or a parking lot?

Thanks!

Re: FindLocationNameExample and OnlineMapsGoogleGeocodingResult

The response contains «place_id».
You need to make a new request to Google Places API to find out detailed information about the object.
OnlineMapsGooglePlaceDetails.FindByPlaceID
http://infinity-code.com/doxygen/online … b9795d0c1d

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: FindLocationNameExample and OnlineMapsGoogleGeocodingResult

Thanks! I'm trying to figure out how to properly use OnlineMapsGooglePlaceDetails.FindByPlaceID.

The documentation says it returns a "Query instance to the Google API." and when I look at it in the code, Visual Studio says it returns an OnlineMapsGooglePlaceDetails type.  OnlineMapsGooglePlaceDetails.GetResult takes a string as a parameter, so I'm not sure how to turn the OnlineMapsGooglePlaceDetails return value from FindByPlaceID into a string I can pass into GetResult. What am I missing here?

Re: FindLocationNameExample and OnlineMapsGoogleGeocodingResult

Absolutely the same way as other Google API requests.

Example:

OnlineMapsGooglePlaceDetails.FindByPlaceID(key, placeID).OnComplete += OnPlaceDetailsComplete;

private void OnPlaceDetailsComplete(string response)
{
    OnlineMapsGooglePlaceDetailsResult result = OnlineMapsGooglePlaceDetails.GetResult(response);
    if (result == null)
    {
        Debug.LogWarning("Something wrong:\n" + response);
        return;
    }
    Debug.Log(string.Join(", ", result.types));
}
Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: FindLocationNameExample and OnlineMapsGoogleGeocodingResult

Thanks very much!

Re: FindLocationNameExample and OnlineMapsGoogleGeocodingResult

Trying out that code, I'm still not finding what I'm looking for. When I click on a nearby park, instead of being told that it's a park and the name of it, I see output like:

administrative_area_level_2, political
administrative_area_level_1, political, point_of_interest, establishment
neighborhood, political

And more like that. Do I need to make another call to find out that it's a park or a hospital or a graveyard?

Thanks again!

Re: FindLocationNameExample and OnlineMapsGoogleGeocodingResult

I see.
The problem is that you are using the wrong service.
Google Geocoding API returns the address.
To find objects near the location, you need to use Google Places API.
Example:

using UnityEngine;

public class GetLocationInfo:MonoBehaviour
{
    public string key;

    private void Start()
    {
        OnlineMapsControlBase.instance.OnMapClick += OnMapClick;
    }

    private void OnMapClick()
    {
        OnlineMapsGooglePlaces.FindNearby(OnlineMapsControlBase.instance.GetCoords(), 20, key).OnComplete += OnFindNearbyComplete;
    }

    private void OnFindNearbyComplete(string response)
    {
        Debug.Log(response);
        OnlineMapsGooglePlacesResult[] results = OnlineMapsGooglePlaces.GetResults(response);
        foreach (OnlineMapsGooglePlacesResult result in results)
        {
            Debug.Log(result.name);
            Debug.Log(string.Join(", ", result.types));
        }
    }
}
Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: FindLocationNameExample and OnlineMapsGoogleGeocodingResult

Sweet, I'll give that a shot. Thanks again!

Re: FindLocationNameExample and OnlineMapsGoogleGeocodingResult

Well, that gets me part of the way there. It seems to work okay on buildings- I click on a dentist and I get:

dentist, health, point_of_interest, establishment

But I click on a golf course and I get:

locality, political
neighborhood, political

If I go to OpenStreetMaps and use their Query Features button, I click on a golf course and I get:

Nearby features
Cycle Path #189157195
Golf Course Balboa Municipal Golf Course
Sand #317312157
Grass #317312158
Grass #317312623
Enclosing features
Golf Course Balboa Municipal Golf Course
City Boundary Los Angeles
County Boundary Los Angeles County
State Boundary California
Timezone America/Los_Angeles Timezone
Country Boundary United States of America

So it looks like for what I'm trying to do an OSM query might be the way to go. Is the means of doing so using those functions similar to what you provided for the Google Places API?

Thanks!

Re: FindLocationNameExample and OnlineMapsGoogleGeocodingResult

I see the example in the Atlas, but it's a bit hard to wrap my brain around.

This bit looks for highways on the visible portion of the map, but the first part of the query I don't understand:

            // Create OSM Overpass request where highway is primary or residential
            string requestData = String.Format("node({0},{1},{2},{3});way(bn)[{4}];(._;>;);out;",
            bottomRight.y, topLeft.x, topLeft.y, bottomRight.x, "'highway'~'primary|residential'");

Could I copy this example, but change the four corner coordinates to be the single point of the click? I guess I'd also remove the bit at the end specifying highways? I'll try some experiments and look into the Overpass API documentation, but if you could provide a brief example that does with OSM what we were discussing with Google, I'd be obliged.

Thanks again!

Re: FindLocationNameExample and OnlineMapsGoogleGeocodingResult

I made a little research, and for your purposes it's best to use Foursquare.
Online Maps does not have classes to work with this web service, but that does not mean that you can not use it.
Example:

using System;
using UnityEngine;

public class GetInfoFromFoursquare:MonoBehaviour
{
    public string clientID;
    public string clientSecret;

    private void Start()
    {
        OnlineMapsControlBase.instance.OnMapClick += OnMapClick;
    }

    private void OnMapClick()
    {
        Vector2 coords = OnlineMapsControlBase.instance.GetCoords();
        OnlineMapsWWW www = new OnlineMapsWWW("https://api.foursquare.com/v2/venues/search?ll=" + coords.y + "," + coords.x + "&client_id=" + clientID + "&client_secret=" + clientSecret + "&v=" + DateTime.Now.ToString("yyyyMMdd") + "&limit=1");
        Debug.Log(www.url);
        www.OnComplete += OnRequestComplete;
    }

    private void OnRequestComplete(OnlineMapsWWW www)
    {
        if (!string.IsNullOrEmpty(www.error))
        {
            Debug.Log(www.error);
            return;
        }

        Debug.Log(www.text);
        OnlineMapsJSONItem json = OnlineMapsJSON.Parse(www.text);
        OnlineMapsJSONItem venue = json["response/venues/0"];
        if (venue != null)
        {
            Debug.Log(venue["name"]);
            Debug.Log(venue["categories/0/shortName"]);
        }
    }
}

P.S. To get id and secret you need to create an application.
https://foursquare.com/developers/register

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: FindLocationNameExample and OnlineMapsGoogleGeocodingResult

Thanks again for your top-notch support. I'll try this out and let you know again if I run into any snags.

Re: FindLocationNameExample and OnlineMapsGoogleGeocodingResult

Thanks for that example, it's especially useful to use as a guide for when I want to use a resource for which there are no classes native to Online Maps.

It doesn't seem to give me what I can get from OSM, though. To give you an example, the area I'm testing in has some features that work perfectly when I do a Query Feature via OSM, but return misleading results when using the Foursquare code above.

An example. Set the Tileset control to:

latitude 34.1820437820025
longitude -118.478416533137
zoom 17
provider OSM
type Mapnik

Clicking in the red national guard station near the top of the map using the Foursquare Code gives me

Carlo Inc
Office 

and when I query feature in OSM I get

Nearby features
No features found
Enclosing features
Military Area Sepulveda Air National Guard Station
{etc}

If I click in the middle of the big Water Reclamation Plant in the center of the map, using the Foursquare code, I get

Woodley Avenue Park
Park

but when I query feature on OSM I get:

Nearby features
Service Road #94233762
Industrial #306664814
Enclosing features
Industrial Area Tillman Water Reclamation Plant
{etc}

I think what's going on is that there aren't as many map features defined (who'd want to "check in" to a water treatment plant?), and it's returning the nearest one, without quite so much detail, as Foursquare doesn't have the boundaries of each feature defined the way OSM does. That means if the point is closer to the center of one feature, Foursquare can't tell you're within the boundaries of another feature.

Is there a way for me to get the results yielded doing a Feature Query on OSM?

Looking here:
https://blog.openstreetmap.org/2014/12/ … y-feature/

Leads me to here:
http://wiki.openstreetmap.org/wiki/Downloading_data

But I'm not sure if that's the right path to victory here. If you can give me an example of that Feature Query tool using Online Maps, I think I'll have what I need to move forward.

Thanks again, and I hope this thread has proved instructive to others who might be reading along. smile

Re: FindLocationNameExample and OnlineMapsGoogleGeocodingResult

I found an *incredibly* useful web site to help me experiment with OSM queries- not sure if you reference in the documentation, but if not, you might want to add it:

http://overpass-turbo.eu/

This might give me what I need to get what I want. Here's the code they give to get all data in a bounding box:

/*
This is a simple map call.
It returns all data in the bounding box.
*/
[out:xml];
(
  node({{bbox}});
  <;
);
out meta;

But I'm not sure how to specify the bounding box using your API. Let me know if I'm barking up the right tree and if you can help me specify the bounding box using the syntax they describe and the corners of the Tileset map.

Thanks again!

Re: FindLocationNameExample and OnlineMapsGoogleGeocodingResult

Their Export tab works not only with the data but with the query. Exporting the above query to text gets me this, which seems to be working for me to get everything, it's a matter of parsing through the data at that point.

string requestData = "(node(34.16870691998642, -118.50798726081847, 34.17677564022297, -118.49230170249939);<;);out meta;";

If you see any reason I shouldn't be continuing this line of inquiry, do let me know. Thanks!

Re: FindLocationNameExample and OnlineMapsGoogleGeocodingResult

The link to overpass-turbo is already in the documentation.
This is a very useful and convenient web service.

Only you know which web service is best for your application.
If you think you need OSM Overpass, just use it.

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.