CitySearch
AMap.CitySearch
Construct an IP location service object
new AMap.CitySearch()Method
getLocalCity(cbk)
Automatically obtain the user's IP, and the callback returns the current city of the user. When status is complete, the result is CitySearchResult; when status is error, the result is error info; when status is no_data, it means the search returned 0 results
Parameter:
cbk (function (status: String, result: info/CitySearchResult): Callback function
Demo:
citySearch.getLocalCity(function (status, result) {
console.log(status, result);
//status: complete indicates a successful query, no_data indicates no results found, error represents a query error
//When the query is successful, the result is location-related information
});getCityByIp(ip, CitySearchCallback)
Returns the corresponding city information based on the input IP address, status as above
Parameter:
ip (String): IP address
CitySearchCallback: Callback function
Demo:
citySearch.getCityByIp("IP address", function (status, result) {
//status: complete indicates a successful query, no_data indicates no results, and error represents a query error
//When the query is successful, the result is the location-related information
});Event
CitySearchResult
CitySearchResult object(Type: Object)