Working with the Google Location API

前端 未结 6 2168
别跟我提以往
别跟我提以往 2021-02-06 05:50

Forgive me for my ignorance, but after several hours of searching, I\'m having little luck.

Anyway, I am attempting to write a small desktop application that will allow

6条回答
  •  故里飘歌
    2021-02-06 06:10

    The Geocode API is rather simple, to get lat/lon from the api you only need to 3 params: output, sensor and address.

    output the output format you want, json or xml (IIRC)

    sensor should be a boolean indicating weather or not the value comes from a sensor such as a GPS chip.

    address should be the address (don't forget to url encode it) you wish to geocode.

    This is an example, where I geocode my office address, and get JSON in response: http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=1+Maritime+Plaza+San+Francisco+CA

    If you navigate to that you should see something like:

    {
      "status": "OK",
      "results": [ {
        "types": [ "street_address" ],
        "formatted_address": "1 Maritime Plaza, San Francisco, CA 94111, USA",
        "address_components": [ {
          "long_name": "1",
          "short_name": "1",
          "types": [ "street_number" ]
        }, {
          "long_name": "Maritime Plaza",
          "short_name": "Maritime Plaza",
          "types": [ "route" ]
        }, {
          "long_name": "San Francisco",
          "short_name": "San Francisco",
          "types": [ "locality", "political" ]
        }, {
          "long_name": "San Francisco",
          "short_name": "San Francisco",
          "types": [ "administrative_area_level_3", "political" ]
        }, {
          "long_name": "San Francisco",
          "short_name": "San Francisco",
          "types": [ "administrative_area_level_2", "political" ]
        }, {
          "long_name": "California",
          "short_name": "CA",
          "types": [ "administrative_area_level_1", "political" ]
        }, {
          "long_name": "United States",
          "short_name": "US",
          "types": [ "country", "political" ]
        }, {
          "long_name": "94111",
          "short_name": "94111",
          "types": [ "postal_code" ]
        } ],
        "geometry": {
          "location": {
            "lat": 37.7953907,
            "lng": -122.3991803
          },
          "location_type": "ROOFTOP",
          "viewport": {
            "southwest": {
              "lat": 37.7922431,
              "lng": -122.4023279
            },
            "northeast": {
              "lat": 37.7985383,
              "lng": -122.3960327
            }
          }
        }
      } ]
    }
    

    If you take the lat/lon provided and place it on a map you see a pointer on my office building.

提交回复
热议问题