How to get Address name using GPS with wp7

2019-02-15 02:21发布

问题:

I can get the current GPS coordinates on Windows Phone 7 using GeoCoordinateWatcher class as shown on msdn, I can only get Latitude and Longitude values, but I want to get Address of that location. There is a free application on market named "Where Am I" it shows Address names too, so I think its possible.
How I do that?

回答1:

You can use Google or Yahoo APIs

http://maps.google.com/maps/geo?q=20.0,2.0&output=json&oe=utf8&sensor=true&key=YOURKEY

http://where.yahooapis.com/geocode?q=20.0,2.0&flags=J&gflags=R&appid=YOURKEY

Here is a sample json response from Google

{
    "name": "20.00,2.00",
    "Status": {
        "code": 200,
        "request": "geocode"
    },
    "Placemark": [
        {
            "id": "p1",
            "address": "Adrar des Ifôghas, Mali",
            "AddressDetails": {
                "Accuracy": 0,
                "AddressLine": [
                    "Adrar des Ifôghas"
                ]
            },
            "ExtendedData": {
                "LatLonBox": {
                    "north": 22.6604651,
                    "south": 17.2938071,
                    "east": 6.0979005,
                    "west": -2.0979005
                }
            },
            "Point": {
                "coordinates": [
                    2,
                    20,
                    0
                ]
            }
        }
    ]
}

EDIT

You can use WebClient to get the result

WebClient w = new WebClient();
string page = w.DownloadString(url);

Here are the samples to parse the Json result

Google Maps v3 geocoding server-side

Looking for a REST with JSON client library