1. userlocation 1) obtain the user's location 2) Tracking users' movements 2. userlocation API Locationmanager: Manages user location services Locationproviders: Other positioning Methods Positioning classification (the first two are the main ones ): A. GPS positioning (precise) B. Network Positioning (rough) C. Passive (passive) Steps: A. Declare the corresponding permissions in the main configuration file. <Uses-Permission Android: Name = "android. Permission. access_fine_location"/> B. Get the locationmanager object C. Select locationprovider D. Bind The locationlistener object. Obtain the longitude and latitude Location. getlongdistance () // longitude Location. getlatitude () // latitude The demo uses ddms to simulate 3. Use criteria (find the best location method) Set query conditions for some columns to find the locationprovider that meets the conditions in the current device. Setaccuracy () // sets the precision Setaltituderequired () // do you need to set the altitude? Setbearingrequired () // whether to set the speed Setcostallowed () // sets whether to generate charges Core Code : /** * Generate a criteria object * Used for multi-condition queries */ Criteria = new criteria (); /** Set the query precision to high precision */ Criteria. setaccuracy (criteria. accuracy_fine ); /** Set power consumption */ Criteria. setpowerrequirement (criteria. power_low ); /** Set whether the altitude is required */ Criteria. setaltituderequired (false ); /** Set whether the speed is required */ Criteria. setspeedrequired (false ); /** Set whether charge is required */ Criteria. setcostallowed (false ); /** * False is not related to whether a provider is enabled. * Only search for the most appropriate */ String provider = locationmanager. getbestprovider (criteria, false ); 4. Introduction to the geocoding Service 1) two main functions are provided: A. query the longitude and latitude of an address B. query the specific address of a longitude and latitude. Method 1: geocoder Core methods: Getfromlocation () Getfromlocationname () Method 2: geocoding (obtained from Google's official website) The web-based geocoder can be directly queried in Google APIs. The Query format is JSON. Steps: A. http://code.google.com/intl/zh-C... entation/geocoding/ B. location can also be achieved through HTTP requests Address Resolution request (obtained on the Google website ): Google geocoding API requests must take the following form: Http://maps.google.com/maps/api/geocode/output? Parameters Output can be one of the following values: JSON (recommended) represents the output in the form of JavaScript Object Notation (JSON) XML indicates output in XML format Some parameters are required and some are optional. According to the URL standard, all parameters are separated by characters. These parameters and their possible values are enumerated below. Google geocoding API uses the following URL parameters to define an address resolution request: Address (required)-the address to be resolved. * Or Latlng (required)-the latitude/longitude text value that you want to obtain, which is closest to, and can be manually read from the address. * Bounds (optional)-the border of the visible area in which the address resolution result is to be significantly offset. (For more information, see the visible area bias below .) Region (optional)-Region code, which is a dual-character value of ccTLD ("top-level domain. (For more information, see the regional bias below .) Language (optional)-language used to return the result. See the list of supported regional languages. Note that the Supported languages are updated frequently, so the list may not be detailed. If language is not provided, the address parser tries to use the local language of the region where the request is sent as much as possible. Sensor (required)-indicates whether the address resolution request comes from a device with a location sensor. The value must be true or false. Note: You can pass the address or latlng for search. (If latlng is passed, the address parser performs Reverse Address Resolution. For more information, see Reverse Address Resolution .) The bounds and region parameters only affect the results returned by the address parser. For example, Beijing (output as follows ): Method 1: JSON format For example: http://maps.google.com/maps/api/... ng & sensor = false { "Results ":[ { "Address_components ":[ { "Long_name": "Beijing ", "Short_name": "Beijing ", "Types": ["locality", "political"] }, { "Long_name": "Beijing ", "Short_name": "Beijing ", "Types": ["administrative_area_level_1", "political"] }, { "Long_name": "China ", "Short_name": "cn ", "Types": ["country", "political"] } ], "Formatted_address": "Beijing, China ", "Geometry ":{ "Bounds ":{ "Northeast ":{ "Lat": 40.21649620, "LNG": 116.78298350 }, "Southwest ":{ "Lat": 39.66127140, "LNG": 116.01193430 } }, "Location ":{ "Lat": 39.9042140, "LNG": 116.4074130 }, "Location_type": "Approximate ", "Viewport ":{ "Northeast ":{ "Lat": 40.21649620, "LNG": 116.78298350 }, "Southwest ":{ "Lat": 39.66127140, "LNG": 116.01193430 } } }, "Types": ["locality", "political"] } ], "Status": "OK" } Method 2: XML format <Geocoderesponse> <Status> OK </status> <Result> <Type> locality </type> <Type> political </type> <Formatted_address> Beijing, China </formatted_address> <Address_component> <Long_name> Beijing </long_name> <Short_name> Beijing </short_name> <Type> locality </type> <Type> political </type> </Address_component> <Address_component> <Long_name> Beijing </long_name> <Short_name> Beijing </short_name> <Type> administrative_area_level_1 </type> <Type> political </type> </Address_component> <Address_component> <Long_name> China </long_name> <Short_name> CN </short_name> <Type> country </type> <Type> political </type> </Address_component> <Geometry> <Location> <Lat> 39.9042140 </LAT> <LNG> 116.4074130 </LNG> </Location> <Location_type> approximate </location_type> <Viewport> <Southwest> <Lat> 39.6612714 </LAT> <LNG> 116.0119343 </LNG> </Southwest> <Northeast> <Lat> 40.2164962 </LAT> <LNG> 116.7829835 </LNG> </Northeast> </Viewport> <Bounds> <Southwest> <Lat> 39.6612714 </LAT> <LNG> 116.0119343 </LNG> </Southwest> <Northeast> <Lat> 40.2164962 </LAT> <LNG> 116.7829835 </LNG> </Northeast> </Bounds> </Geometry> </Result> </Geocoderesponse> |