123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- define(['$','base'], function($, base) {
- var config = {
- suggestion: 'http://api.map.baidu.com/place/v2/suggestion',
- search: 'http://api.map.baidu.com/place/v2/search',
- ak: 'B349f0b32ef6e78b2e678f45cb9fddaf',
- output: 'json',
- query: '',
- region: ''
- };
- var MapApi = function() {
- if (typeof MapApi.instance === 'object') {
- return MapApi.instance;
- }
- MapApi.instance = this;
- this.isLoading = false;
- }
- MapApi.prototype = new base();
- var apiErrorResult = {
- success: false,
- message: '加载哥遇到瓶颈再来一遍嘛 <( ̄︶ ̄)>'
- };
- MapApi.prototype = {
- // 根据城市
- getSuggestionList: function (query, region, callback) {
- var that = this;
- this.isLoading = true;
- $.autoAjax({
- url: config.suggestion,
- data: {
- ak: config.ak,
- output: config.output,
- query: query,
- region: region
- },
- dataType: 'JSON',
- success: function(res) {
- that.isLoading = false;
- if (callback) {
- callback(res);
- }
- },
- error: function(res) {
- that.isLoading = false;
- if (callback) {
- callback(apiErrorResult);
- }
- }
- });
- },
- // 根据坐标
- getPlaceList: function (query, location, callback) {
- var that = this;
- this.isLoading = true;
- $.autoAjax({
- url: config.search,
- data: {
- ak: config.ak,
- output: config.output,
- query: query, // 检索关键字
- page_size: '10', // 返回记录数量,默认为10条记录,最大返回结果为20条。
- page_num: '0', // 分页页码,默认为0,0代表第一页,1代表第二页,以此类推。
- scope: '1', // 检索结果详细程度。取值为1 或空,则返回基本信息;取值为2,返回检索POI详细信息
- location: location, // 周边检索中心点,不支持多个点。
- radius: '2000' // 周边检索半径,单位为米。
- },
- dataType: 'JSON',
- success: function(res) {
- that.isLoading = false;
- if (callback) {
- callback(res);
- }
- },
- error: function(res) {
- that.isLoading = false;
- if (callback) {
- callback(apiErrorResult);
- }
- }
- });
- },
- getSearchList: function (q, region, callback) {
- var that = this;
- this.isLoading = true;
- $.autoAjax({
- url: config.search,
- data: {
- ak: config.ak,
- output: config.output,
- q: q, // 检索关键字,
- region: region
- },
- dataType: 'JSON',
- success: function(res) {
- that.isLoading = false;
- if (callback) {
- callback(res);
- }
- },
- error: function(res) {
- that.isLoading = false;
- if (callback) {
- callback(apiErrorResult);
- }
- }
- });
- }
- }
- return new MapApi();
- });
|