定位大概步奏:
1.通过gps获Ip地址获得当前移动设备的经纬度。
2.通过http访问google地图网址返回的json文件获得解析出来的地址。
主要代码:
public void registerLocationListener
LocationManager locationManager = (LocationManager) context
json文件:
{ "results" : [ { "address_components" : [ { "long_name" : "珠江路", "short_name" : "S320", "types" : [ "route" ] }, { "long_name" : "北仑区", "short_name" : "北仑区", "types" : [ "sublocality", "political" ] }, { "long_name" : "宁波", "short_name" : "宁波", "types" : [ "locality", "political" ] }, { "long_name" : "浙江省", "short_name" : "浙江省", "types" : [ "administrative_area_level_1", "political" ] }, { "long_name" : "中国", "short_name" : "CN", "types" : [ "country", "political" ] } ], "formatted_address" : "中国浙江省宁波市北仑区珠江路", "geometry" : { "bounds" : { "northeast" : { "lat" : 29.90676640, "lng" : 121.86781210 }, "southwest" : { "lat" : 29.90103360, "lng" : 121.86667790 } }, "location" : { "lat" : 29.90390020, "lng" : 121.86724390 }, "location_type" : "APPROXIMATE", "viewport" : { "northeast" : { "lat" : 29.90676640, "lng" : 121.8685939802915 }, "southwest" : { "lat" : 29.90103360, "lng" : 121.8658960197085 } } }, "types" : [ "route" ] }, { "address_components" : [ { "long_name" : "北仑区", "short_name" : "北仑区", "types" : [ "sublocality", "political" ] }, { "long_name" : "宁波", "short_name" : "宁波", "types" : [ "locality", "political" ] }, { "long_name" : "浙江省", "short_name" : "浙江省", "types" : [ "administrative_area_level_1", "political" ] }, { "long_name" : "中国", "short_name" : "CN", "types" : [ "country", "political" ] } ], "formatted_address" : "中国浙江省宁波市北仑区", "geometry" : { "bounds" : { "northeast" : { "lat" : 29.99079930, "lng" : 122.15796280 }, "southwest" : { "lat" : 29.70892750, "lng" : 121.65269810 } }, "location" : { "lat" : 29.8988660, "lng" : 121.8446690 }, "location_type" : "APPROXIMATE", "viewport" : { "northeast" : { "lat" : 29.99079930, "lng" : 122.15796280 }, "southwest" : { "lat" : 29.70892750, "lng" : 121.65269810 } } }, "types" : [ "sublocality", "political" ] }, { "address_components" : [ { "long_name" : "宁波", "short_name" : "宁波", "types" : [ "locality", "political" ] }, { "long_name" : "浙江省", "short_name" : "浙江省", "types" : [ "administrative_area_level_1", "political" ] }, { "long_name" : "中国", "short_name" : "CN", "types" : [ "country", "political" ] } ], "formatted_address" : "中国浙江省宁波市", "geometry" : { "bounds" : { "northeast" : { "lat" : 30.36904030, "lng" : 122.27992880 }, "southwest" : { "lat" : 28.85352960, "lng" : 120.91691940 } }, "location" : { "lat" : 29.8683360, "lng" : 121.543990 }, "location_type" : "APPROXIMATE", "viewport" : { "northeast" : { "lat" : 30.05437520, "lng" : 121.80541990 }, "southwest" : { "lat" : 29.68518539999999, "lng" : 121.3385010 } } }, "types" : [ "locality", "political" ] }, { "address_components" : [ { "long_name" : "浙江省", "short_name" : "浙江省", "types" : [ "administrative_area_level_1", "political" ] }, { "long_name" : "中国", "short_name" : "CN", "types" : [ "country", "political" ] } ], "formatted_address" : "中国浙江省", "geometry" : { "bounds" : { "northeast" : { "lat" : 31.17878220, "lng" : 122.95566510 }, "southwest" : { "lat" : 27.04668010, "lng" : 118.0282790 } }, "location" : { "lat" : 30.265860, "lng" : 120.1536760 }, "location_type" : "APPROXIMATE", "viewport" : { "northeast" : { "lat" : 31.17878220, "lng" : 122.95566510 }, "southwest" : { "lat" : 27.04668010, "lng" : 118.0282790 } } }, "types" : [ "administrative_area_level_1", "political" ] }, { "address_components" : [ { "long_name" : "中国", "short_name" : "CN", "types" : [ "country", "political" ] } ], "formatted_address" : "中国", "geometry" : { "bounds" : { "northeast" : { "lat" : 53.56097399999999, "lng" : 134.77280990 }, "southwest" : { "lat" : 18.15352160, "lng" : 73.49941360 } }, "location" : { "lat" : 35.861660, "lng" : 104.1953970 }, "location_type" : "APPROXIMATE", "viewport" : { "northeast" : { "lat" : 53.56097399999999, "lng" : 134.77280990 }, "southwest" : { "lat" : 18.15352160, "lng" : 73.49941360 } } }, "types" : [ "country", "political" ] } ], "status" : "OK" }