//checks whether an alert is within range static int is_alert_in_range(const RoadMapGpsPosition *gps_position, const PluginLine *line) { int count; int i; int distance ; int steering; RoadMapPosition pos; int azymuth; int delta; int j; unsigned int speed; RoadMapPosition gps_pos; int square; int squares[9]; int count_squares; gps_pos.latitude = gps_position->latitude; gps_pos.longitude = gps_position->longitude; count_squares = roadmap_square_find_neighbours (&gps_pos, 0, squares); for (square = 0; square < count_squares; square++) { roadmap_square_set_current(squares[square]); // loop alll prvidor for an alert for (j = 0 ; j < RoadMapAlertProvidors.count; j++) { count = (* (RoadMapAlertProvidors.providor[j]->count)) (); // no alerts for this providor if (count == 0) { continue; } for (i=0; i<count; i++) { // if the alert is not alertable, continue. (dummy speed cams, etc.) if (!(* (RoadMapAlertProvidors.providor[j]->is_alertable))(i)) { continue; } (* (RoadMapAlertProvidors.providor[j]->get_position)) (i, &pos, &steering); // check that the alert is within alert distance distance = roadmap_math_distance(&pos, &gps_pos); if (distance > (*(RoadMapAlertProvidors.providor[j]->get_distance))(i)) { continue; } // check if the alert is on the navigation route if (!alert_is_on_route (&pos, steering)) { // check that the alert is in the direction of driving delta = azymuth_delta(gps_position->steering, steering); if (delta > AZYMUTH_DELTA || delta < (0-AZYMUTH_DELTA)) { continue; } // check that we didnt pass the alert azymuth = roadmap_math_azymuth (&gps_pos, &pos); delta = azymuth_delta(azymuth, steering); if (delta > 90|| delta < (-90)) { continue; } // check that the alert is on the same street if (!check_same_street(line, &pos)) { continue; } } speed = (* (RoadMapAlertProvidors.providor[j]->get_speed))(i); // check that the driving speed is over the allowed speed for that alert if ((unsigned int)roadmap_math_to_speed_unit(gps_position->speed) < speed) { the_active_alert.alert_type = WARN; the_active_alert.distance_to_alert = distance; the_active_alert.active_alert_id = (* (RoadMapAlertProvidors.providor[j]->get_id))(i); the_active_alert.alert_providor = j; return TRUE; } else { the_active_alert.alert_type = ALERT; the_active_alert.alert_providor = j; the_active_alert.distance_to_alert = distance; the_active_alert.active_alert_id = (* (RoadMapAlertProvidors.providor[j]->get_id))(i); return TRUE; } } } } return FALSE; }
//checks whether an alert is within range static int is_alert_in_range(const RoadMapGpsPosition *gps_position, const PluginLine *line){ int i; int j; unsigned int speed; int distance; // will hold the distance of the alert RoadMapPosition gps_pos; int square; int squares[9]; int count_squares; const char * street_name; // the current street name. char current_street_name[512]; RoadMapPosition context_save_pos; int context_save_zoom; int alert_index; // will hold the index in the provider of the alert int priorities [] = {ALERTER_PRIORITY_HIGH,ALERTER_PRIORITY_MEDIUM,ALERTER_PRIORITY_LOW}; int num_priorities = sizeof(priorities)/sizeof(int); int alert_providor_ind; int square_ind; BOOL found_alert = FALSE; gps_pos.latitude = gps_position->latitude; gps_pos.longitude = gps_position->longitude; roadmap_math_get_context(&context_save_pos, &context_save_zoom); roadmap_math_set_context((RoadMapPosition *)&gps_pos, 20); count_squares = roadmap_square_find_neighbours (&gps_pos, 0, squares); // get the street infromation of the current position. get_street_from_line(line->square,line->line_id, &street_name); strncpy_safe (current_street_name, street_name, sizeof (current_street_name)); // go over priorities one by one from highest to lowest. for (j=0; (j< num_priorities); j++){ if ( found_alert ) // Removed from the "for" condition due to some problem in android gcc AGA break; // loop all the providers for an alert for (i = 0 ; ((i < RoadMapAlertProviders.count)&&(!found_alert)); i++){ // if provider doesn't have a high enough priority skip him, we'll get to him later. if(RoadMapAlertProviders.provider[i]->get_priority()!=priorities[j]) continue; /* * If not enough distance has been passed from last check, provider can order to ignore * if alert is active, always perform check, so distance will be updated */ if(!alert_should_be_visible){ if(!(* (RoadMapAlertProviders.provider[i]->distance_check))(gps_pos)) continue; } if ((* (RoadMapAlertProviders.provider[i]->is_square_dependent))()){ /* * This provider has different alerts for each square, so we need to loop over all * these squares and check. (Speed cams in tiles for example, as opposed to RealTimeAlerts). */ for (square = 0; ((square < count_squares)&&(!found_alert)); square++) { roadmap_square_set_current(squares[square]); if(is_alert_in_range_provider(RoadMapAlertProviders.provider[i], gps_position, line, &alert_index,&distance, current_street_name)) { square_ind = square; alert_providor_ind = i; found_alert = TRUE; } } } else { if(is_alert_in_range_provider(RoadMapAlertProviders.provider[i], gps_position, line, &alert_index,&distance,current_street_name)) { square_ind = square; alert_providor_ind = i; found_alert = TRUE; } } } } if(found_alert){ speed = (* (RoadMapAlertProviders.provider[alert_providor_ind]->get_speed))(alert_index); // if driving speed is over the speed limit - it's an ALERT, otherwise it's a WARNING if ((unsigned int)roadmap_math_to_speed_unit(gps_position->speed) < speed) { the_active_alert.alert_type = WARN; the_active_alert.distance_to_alert = distance; the_active_alert.active_alert_id = (* (RoadMapAlertProviders.provider[alert_providor_ind]->get_id))(alert_index); the_active_alert.alert_provider = alert_providor_ind; the_active_alert.square = squares[square_ind]; roadmap_math_set_context(&context_save_pos, context_save_zoom); return TRUE; } else{ the_active_alert.alert_type = ALERT; the_active_alert.distance_to_alert = distance; the_active_alert.active_alert_id = (* (RoadMapAlertProviders.provider[alert_providor_ind]->get_id))(alert_index); the_active_alert.alert_provider = alert_providor_ind; the_active_alert.square = squares[square_ind]; roadmap_math_set_context(&context_save_pos, context_save_zoom); return TRUE; } } roadmap_math_set_context(&context_save_pos, context_save_zoom); return FALSE; }