Search code examples
javagoogle-mapsgoogle-apigoogle-roads-api

Google Apis Nearest Roads to snap roads


I am new to use Google api nearest roads to snap the roads.

I was trying as in the below link:

Google api for nearest road

If I have to try the

https://roads.googleapis.com/v1/nearestRoads?parameters&key=YOUR_API_KEY

with the api key provided in my Project, I get

{
"error": {
    "code": 403,
    "message": "Roads API has not been used in project **** before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/roads/overview?project=*** then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
    "status": "PERMISSION_DENIED",
    "details": [
        {
            "@type": "type.googleapis.com/google.rpc.Help",
            "links": [
                {
                    "description": "Google developer console API activation",
                    "url": "https://console.developers.google.com/apis/api/roads/overview?project=****"
                }
            ]
        }
    ]
}

replaces the key used.

What am I missing here? Should I verify the key somewhere before using? Or if I want to just try out the samples how do I get the key?


Solution

  • "Roads API has not been used in project **** before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/roads/overview?project=*** then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",

    This error message is a little confusing. Before you can access an API you need to enable it in your project on Google developer console. To do that

    1. Go to https://console.developers.google.com/apis/dashboard
    2. make sure your project is selected at the top.
    3. Go to library
    4. search for roads api
    5. Enable it.

    Wait a few minutes and your code should then work

    Detailed info:

    When you want to access Google data google needs to know who you are. And what your project will be doing. They do that by asking you to create a project on google developer console. In that project you can define the apis you will be using and you can also request api keys and client ids which will allow you to access data. In this instance you are having an issue with the set up of your project on google developer console it has nothing to do with your code.