WEB开发网
开发学院手机开发Android 开发 Android Wifi定位 阅读

Android Wifi定位

 2010-08-23 01:31:00 来源:WEB开发网   
核心提示:position_cache_->FindPosition(radio_data_, wifi_data_); 3 data_mutex_.Unlock(); 4 if (cached_position) { 5 assert(cached_position->IsGoodFix()); 6 // Reco
position_cache_->FindPosition(radio_data_, wifi_data_); 3 data_mutex_.Unlock(); 4 if (cached_position) { 5 assert(cached_position->IsGoodFix()); 6 // Record the position and update its timestamp. 7 position_mutex_.Lock(); 8 position_ = *cached_position; 9 position_.timestamp = timestamp_;10 position_mutex_.Unlock();11 12 // Let listeners know that we now have a position available.13 UpdateListeners();14 return true;15 }

如果找不到,再做实际的请求

1 return request_->MakeRequest(access_token,2 radio_data_,3 wifi_data_,4 request_address_,5 address_language_,6 kBadLatLng, // We don't have a position to pass7 kBadLatLng, // to the server.8 timestamp_);

7.客户端协议包装

前面的request_是NetworkLocationRequest实例,先看 MakeRequest的实现:

先对参数进行打包:

1 if (!FormRequestBody(host_name_, access_token, radio_data, wifi_data,2 request_address, address_language, latitude, longitude,3 is_reverse_geocode_, &post_body_)) {4 return false;5 }

通知负责收发的线程

1 thread_event_.Signal();

8.负责收发的线程

1 void NetworkLocationRequest::Run() { 2 while (true) { 3 thread_event_.Wait(); 4 if (is_shutting_down_) { 5 break; 6 } 7 MakeRequestImpl(); 8 } 9 }10 11 void NetworkLocationRequest::MakeRequestImpl() {12 WebCacheDB::PayloadInfo payload;

把打包好的数据通过HTTP请求,发送给服务器

1 scoped_refptr payload_data; 2 bool result = HttpPost(url_.c_str(), 3 false, // Not capturing, so follow redirects 4 NULL, // reason_header_value 5 HttpConstants::kMimeApplicationJson, // Content-Type 6 NULL, // mod_since_date 7 NULL, // required_cookie 8 true, // disable_browser_cookies 9 post_body_.get(),10 &payload,11 &payload_data,12 NULL, // was_redirected13 NULL, // full_redirect_url14 NULL); // error_message15 16 MutexLock lock(&is_processing_response_mutex_);17 // is_aborted_ may be true even if HttpPost succeeded.18 if (is_aborted_) {19

上一页  1 2 3 4 5 6 7  下一页

Tags:Android Wifi 定位

编辑录入:coldstar [复制链接] [打 印]
赞助商链接