An "Is This Allowed?" Question (more details in the post)

18 posts / 0 new
Last post
DragonOsman
An "Is This Allowed?" Question (more details in the post)

I just want to ask if what I want to do is allowed first.  So for now I'll just explain what I wan to do with this API and ask if it's allowed.

My web app is a Google Maps Currency Converter application.  I use Reverse Geocoding to get the name of a place through its lat and lng coordinates and pass that name to a function that returns a currency abbreviation.  With Google's Geocoding service, I'm getting a "ZERO_RESULTS" status code when I try to use reverse geocoding on Kosovo, Western Sahara and Wake Island (I get an empty JSON object).  What I want to do is to use MapQuest's Reverse Geocoding API in the case where I get that "ZERO_RESULTS" status code come up.  

So yeah: is this allowed?  Or should I not do this?


MQBrianCoakley
Yes, this is allowed. A
Yes, this is allowed. A "Powered by MapQuest", or similar, is required when displaying the results if they're not on a MapQuest map.

DragonOsman
Thanks for the reply.

Thanks for the reply.

I saw the URL I need to use, but where can I find documentation on the class constructor for the Geocoder?  And the code I need to use?  Also, do I just put "Powered by MapQuest" in the HTML code directly?  Is putting it right before the closing body tag okay if so?


MQBrianCoakley
It should be displayed where
It should be displayed where the functionality is used. There is no specific mention of it in the T&Cs but that's the spirit of the requirement.

DragonOsman
I'm going to use the

I'm going to use the functionality in the JavaScript code.  But I think it's better to put that line in the HTML code.  It's a single-page application anyway, so people will still see it where the MapQuest functionality is being used.  

I'd like to know how to actually do reverse geocoding here in JavaScript code.  I saw in the geocoder class constructor that appears when I first go to the developer section that I need a location and a callback (the callback seems to be for having the map appear).  I don't need the callback, so hopefully it's an optional parameter to the function.  It was the forward geocoder constructor, though, so the name of the place was being passed in.  Where can I find documentation on how to use the reverse geocoder in code?

I also made a comment about the JSON data returned for using the preview reverse geocoder on here, for Kosovo and Western Sahara.  There's an empty string stored for "adminArea3", so I'll probably have to consider them as part of the country whose ISO abbreviation is used for it ("SR" for Kosovo and "MA" for Western Sahara--Serbia and Morocco, respectively).  Though I could also just store the correct string in "adminArea3" and use that.  What do you think?


MQBrianCoakley
There is an example showing

There is an example showing the reverse geocoder here.

 

The country or adminArea1 should be enough to determine currency most of the time.


DragonOsman
Yes, most of the time

Yes, most of the time "adminArea1" should be enough.  

Thanks for the link.


DragonOsman
Is this function all I need?

Is this function all I need? "L.mapquest.geocoding().reverse(e.latlng, generatePopupContent);". And if so, what should I pass as the callback?  Should I show my code to show what I have so you can help me better from that?


MQBrianCoakley
The sample code in the user
The sample code in the user guide shows how you might handle the response in the generatePopupContent function. It will contain the location and the country can be pulled from there.

DragonOsman
Is there no way to use a

Is there no way to use a callback that won't generate a popup?


MQBrianCoakley
No need for the popup. Remove
No need for the popup. Remove references to the popup and at the end of the callback function send that data wherever you want. For example: alert(street + ', ' + city + ', ' + state);

DragonOsman
I don't even want to use an

I don't even want to use an alert or any other kind of popup, I just want the data.  Here's the JS code Gist: https://gist.github.com/DragonOsman/c6e8fb15343544e662f474c5a526d1c2 ; I'm going to use MapQuest's reverse geocoder in the else clause on line 1195.  


MQBrianCoakley
If you don't need any of the
If you don't need any of the MapQuest functionality then it becomes a JavaScript question rather than a MapQuest question. You can reduce the generatePopupContent function to just console.log(response.results[0].locations[0].adminArea1); where you're just parsing the JSON returned.

DragonOsman
I need the MapQuest

I need the MapQuest functionality for only the reverse geocoding on the three aforementioned places.  And I just need the data from the reverse geocoding and nothing else.  


DragonOsman
I tried doing it the way I

I tried doing it the way I thought I had to do it.  Please let me know if I have it right.  Gist link: https://gist.github.com/DragonOsman/c6e8fb15343544e662f474c5a526d1c2 .  The code for using the MapQuest Reverse Geocoding is inside the else clause on line 1195.  You'll have to read the whole code to understand what's going on, though, of course.  The object "location" is an object lat and long coordinates; it's initalized on line 1011 and passed in to the "fill_info_window" function.  The MapQuest Key is stored inside an environment variable in the backend web server application that I wrote, so I have to request it from there; hence the XHR stuff (same for the accesskey for the currency API).  


DragonOsman
I have an error message in

I have an error message in the console that says

SCRIPT5022: Invalid LatLng object: (function (){return a}, function (){return b})

and it's coming from mapquest.js, line 10 in the pretty-printed version.  Apparently, my "location" object became an invalid LatLng object.  Is there something inside the global "L" object that can let me access the LatLng object?  I could assign the location object's latitude and longitude values to it on a line where it's valid and then try it again.  


DragonOsman
Sorry for the double post,

Sorry for the double post, but I have something to add here.

I tried reverse geocoding Kosovo, Western Sahara and Wake Island.  Wake Island's is fine, but Kosovo and Western Sahara's JSON results are going to give me problems.  

Kosovo's:

{
  "info": {
    "statuscode": 0,
    "copyright": {
      "text": "© 2018 MapQuest, Inc.",
      "imageUrl": "http://api.mqcdn.com/res/mqlogo.gif",
      "imageAltText": "© 2018 MapQuest, Inc."
    },
    "messages": []
  },
  "options": {
    "maxResults": 1,
    "thumbMaps": false,
    "ignoreLatLngInput": false
  },
  "results": [
    {
      "providedLocation": {
        "latLng": {
          "lat": 42.58151,
          "lng": 20.89153
        }
      },
      "locations": [
        {
          "street": "R 102",
          "adminArea6": "",
          "adminArea6Type": "Neighborhood",
          "adminArea5": "Drenas",
          "adminArea5Type": "City",
          "adminArea4": "",
          "adminArea4Type": "County",
          "adminArea3": "",
          "adminArea3Type": "State",
          "adminArea1": "RS",
          "adminArea1Type": "Country",
          "postalCode": "13000",
          "geocodeQualityCode": "B1AAA",
          "geocodeQuality": "STREET",
          "dragPoint": false,
          "sideOfStreet": "N",
          "linkId": "0",
          "unknownInput": "",
          "type": "s",
          "latLng": {
            "lat": 42.580687,
            "lng": 20.89503
          },
          "displayLatLng": {
            "lat": 42.580687,
            "lng": 20.89503
          }
        }
      ]
    }
  ]
}

Western Sahara's:

{
  "info": {
    "statuscode": 0,
    "copyright": {
      "text": "© 2018 MapQuest, Inc.",
      "imageUrl": "http://api.mqcdn.com/res/mqlogo.gif",
      "imageAltText": "© 2018 MapQuest, Inc."
    },
    "messages": []
  },
  "options": {
    "maxResults": 1,
    "thumbMaps": false,
    "ignoreLatLngInput": false
  },
  "results": [
    {
      "providedLocation": {
        "latLng": {
          "lat": 24.66245,
          "lng": -13.13556
        }
      },
      "locations": [
        {
          "street": "",
          "adminArea6": "",
          "adminArea6Type": "Neighborhood",
          "adminArea5": "",
          "adminArea5Type": "City",
          "adminArea4": "Gueltat Zemmour",
          "adminArea4Type": "County",
          "adminArea3": "Laâyoune - Boujdour - Sakia El Hamra",
          "adminArea3Type": "State",
          "adminArea1": "MA",
          "adminArea1Type": "Country",
          "postalCode": "",
          "geocodeQualityCode": "A4XAX",
          "geocodeQuality": "COUNTY",
          "dragPoint": false,
          "sideOfStreet": "N",
          "linkId": "0",
          "unknownInput": "",
          "type": "s",
          "latLng": {
            "lat": 24.66245,
            "lng": -13.13556
          },
          "displayLatLng": {
            "lat": 24.66245,
            "lng": -13.13556
          }
        }
      ]
    }
  ]
}

For Wake Island it clearly says, for "adminArea3", that it's "United States Minor Outlying Islands".  I guess I could just consider Kosovo as a part of Serbia and Western Sahara as a part of Morocco (although a part of Western Sahara is occupied by Sahrawi Arab Democratic Republic too), but I wonder if I can't do better.  


MQBrianCoakley
The Open Geocode api or the
The Open Geocode api or the Nominatim api may return different/better results. Those may be worth a test.