Correct address format to get the most accurate results from google GeoCoding API

前端 未结 6 839
南笙
南笙 2020-12-24 02:12

Is there any standard format to supply the address string to Google GeoCoding API to get the most accurate results on map.

For Eg. following query not giving correct

6条回答
  •  萌比男神i
    2020-12-24 02:59

    I stumbled upon this question and found a solution that worked for me:

    I think the answer can be found by using component filtering, look at: https://developers.google.com/maps/documentation/geocoding/#ComponentFiltering

    An example in Javascript:

    var request = require('request');
    
    var url = "https://maps.googleapis.com/maps/api/geocode/json?" +
        "address=Herengracht 180" +
        "&components=postal_code:1016 BR|country:NL" +
        "&sensor=false";
    
    request(url, function (error, response, body) {
      if (!error && response.statusCode == 200) {
        console.log(body);
      }
      else {
        console.log('error', error);
      }
    });
    

提交回复
热议问题