Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade the API from v2.0 to v3.0 #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

womeimingzi11
Copy link

The Baidu Maps API geocoding services and reverse geocoding has been upgraded from v2 to v3. The v2.0 API is unavailable for users who registered after 2019.06.18. To guarantee the experience and availability, I highly recommend upgrading the API in baidugeo synchronously.

@womeimingzi11
Copy link
Author

Please notice, as the documents of Baidu Map API revealing the global reverse geocoding POI service is available after July 2, 2020, the AKs registered before then have no permission to use it by default. If anyone who needs to use the service for AKs registered before then, please go to the API console and select "global reverse geocoding POI service" for AKs, then this service will be available.

So why should we switch the older reverse geocoding to the current version, viz., from v2.0 to v3.0? Because the 'reverse_geocoding/v3' entry has been removed from current documents, which means it has been already deprecated.

@ChrisMuir
Copy link
Owner

ChrisMuir commented Sep 28, 2020

Hey, thank you so much for bringing this to my attention. So I only have access to a key that was registered prior to 2019. For me, API calls made with /geocoder/v2/ still work just fine, but calls made with the updated /geocoding/v3/ fail with message:

Error: API key is invalid. Current API key: <my-valid-key>
    Response from the API:
    APP 服务被禁用

This is the same response reported in issue #5, so I assume the API is returning the same error response when you use a "new" key with the /geocoder/v2/ API url.

I worked on edits that will set a version (v2 or v3) as a env var, and will dynamically flip between the v2 and v3 url string if an API call returns the 服务被禁用 response. I just pushed to branch api-upgrade-test, can you try cloning the repo and testing out that branch, with a "new" v3-compatible API key? Thanks again!

@ChrisMuir
Copy link
Owner

@womeimingzi11 Opened a new PR off my branch, here. Give it a try and let me know if it works with a v3 AK key.

@womeimingzi11
Copy link
Author

@ChrisMuir I am so sorry for my unworkable PR. With your new branch, bmap_get_coords works well. That's great!

Unfortunatly, bmap_get_location sitll returns this:

Request Parameter Error: lack address or location

I guess this is caused by the breaking upgrade of API of Baidu Map. I find the geocode and reverse-geocode services have been seperated in v3.

For geocoding service, the base url is:

http://api.map.baidu.com/geocoding/v3/

And the argument name of address is address.

For reverse geocoding service, the base url is:

http://api.map.baidu.com/reverse_geocoding/v3/

And the argument for coordinate is location, and the structure of this value is a string like: longitude comma latitude.

I hope that helps.

To apologize for my unworkable PR again.

@ChrisMuir
Copy link
Owner

No worries, your PR was still very helpful since it brought the issue to my attention. I don't personally use the Baidu API anymore, so was unaware of the upgrade, so thanks!

And thank you for the feedback and details on the reverse geocoding, yeah I'm still using http://api.map.baidu.com/geocoding/v3/ as the base url for the reverse geocoding calls, so that's probably what's causing the failures.

I actually can't get the Baidu API docs to load in my browser. This is the url constructor for v3 that I'm using (after updating the base url):

uri <- paste0(
  "http://api.map.baidu.com/reverse_geocoding/v3/?ak=", 
  "%s", 
  "&location=", 
  lat, 
  ",", 
  lon, 
  "&output=json&coordtype=wgs84ll"
)

I noticed in your notes, you indicated longitude comma latitude....is that accurate, according to the API docs? v2 required those values in the opposite order as the string latitude comma longitude.

@womeimingzi11
Copy link
Author

womeimingzi11 commented Sep 28, 2020 via email

@ChrisMuir
Copy link
Owner

Just pushed to my open branch/PR to update the reverse geocoding base url. Try pulling that down and giving that a test, when you get a chance.

@womeimingzi11
Copy link
Author

womeimingzi11 commented Sep 29, 2020 via email

@ChrisMuir
Copy link
Owner

Hello @womeimingzi11 , I'm going back through my old repos and wanted to check in with you on this. Did you ever have a chance to pull down the branch from my PR-6, to test the reverse geocoding? Thanks!

@womeimingzi11
Copy link
Author

womeimingzi11 commented Dec 22, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants