Crime library

workflow name likes popularity pub points

Introduction

Package to make Crime data requests, this API lets you retrieve crime information from 250+ cities across the US and LATAM. The API exposes four methods to retrieve raw crime date, crime statistics, crime coverage information, and crowdsourced crime data.

It's implementing the methods from the following known Crime data API provider crimeometer.com.

It has a FREE API key for testing purposes that can be found in the previous link. Contact the API provider to get more information about unlimited requests and their prices.

Installation

dependencies:
  crime: 0.1.3

Example

See example/main.dart

import 'package:crime/crime.dart';

void main() async {
  try {
    const String API_KEY = "XXXXXXXXXXXXXXX"; // Your private API Key.

    final Crime crime = Crime(apiKey: API_KEY);

    final CrimeRawIncidents crimeIncidents = await crime.getCrimeIncidents(
      37.773972,
      -122.431297,
      "50mi",
      DateTime(2021, 1, 1),
      DateTime(2021, 2, 7),
    );

    crimeIncidents.incidents?.forEach((CrimeRawData crimeData) {
      print(
          "Crime incident [${crimeData.incidentOffense}] at [${crimeData.cityKey}]");
    });
  } catch (e) {
    print(e);
  }
}

Methods

Constructor

Library crime class constructor, includes a mandatory parameter to set the apiKey.

Crime({this.apiKey});

getCrimeCoverageData

Method to fetch crime coverage data from the cities of the U.S, and a few cities in LATAM: Sao Paulo (Brazil), Rio de Janeiro (Brazil), Buenos Aires (Argentina), Santiago (Chile), Montevideo (Uruguay), León (Mexico) and others.

Future<List<CrimeCoverage>> getCrimeCoverageData();

getCrimeIncidents

A method to obtain crime incident data from a specific location, over a range of distance, and over a period of time.

Future<CrimeRawIncidents> getCrimeIncidents(double latitude, double longitude, String distance, DateTime startDateTime, DateTime endDateTime, {int page = 1});

getCrimeStats

Method to fetch crime statistics from a specific location, over a range of distance, and over a period of time.

Future<CrimeStats> getCrimeStats(double latitude, double longitude, String distance, DateTime startDateTime, DateTime endDateTime, {int source = 1});

getCrowdsourcedCrimeIncidents

A method to obtain unofficial crime incident data from a specific location, over a range of distance, and over a period of time. This information is collected from the community through CityCop app.

Future<CrimeCrowdIncidents> getCrowdsourcedCrimeIncidents(double latitude, double longitude, String distance, DateTime startDateTime, DateTime endDateTime, {int page = 1});

Responses

CrimeCoverage

AttributeTypeDescription
cityNameStringThe name of the city.
incidentsQuantityintThe amount of incidents.
cityKeyStringThe key value of the city.
firstIncidentDateDateTimeThe date of the first incident.
lastIncidentDateDateTimeThe date of the last incident.

CrimeRawIncidents

AttributeTypeDescription
totalIncidentsintTotal number of incidents.
totalPagesintTotal number of pages for the request.
incidentsList<CrimeRawData>List of incidents.

CrimeRawData

AttributeTypeDescription
cityKeyStringCity code in UN/LOCODE standard.
incidentCodeStringIncident code provided by the source.
incidentDateDateTimeIncident occurred date (aprox.).
incidentOffenseStringIncident offense type using FBI-NIBRS standard.
incidentOffenseCodeStringIncident offense code using FBI-NIBRS standard.
incidentOffenseDescriptionStringIncident offense sub type using FBI-NIBRS standard.
incidentOffenseDetailDescriptionStringIncident detail description.
incidentOffenseCrimeAgainstStringIncident against Person/Property/Society/Not a Crime.
incidentOffenseActionStringIncident action status (Commited/Attempted).
incidentSourceOriginalTypeStringType of incident from the original source.
incidentSourceNameStringIncident source name.
incidentLatitudedoubleIncident latitude.
incidentLongitudedoubleIncident longitude.
incidentAddressStringIncident address (approximate in some cases).

CrimeCrowdIncidents

AttributeTypeDescription
totalIncidentsintTotal number of incidents.
totalPagesintTotal number of pages for the request.
incidentsList<CrimeRawCrowdData>List of incidents.

CrimeRawCrowdData

AttributeTypeDescription
incidentCodeStringIncident code provided by the source.
incidentLatitudedoubleIncident latitude.
incidentLongitudedoubleIncident longitude.

CrimeStats

AttributeTypeDescription
totalIncidentsintTotal number of incidents.
reportTypesList<CrimeReportType>List of incidents offenses.

CrimeReportType

AttributeTypeDescription
typeStringIncident offense description.
countintTotal number of incidents by offense description.

Exceptions

  • MandatoryApiKeyException: missing mandatory API Key.
  • ForbiddenRequestException: Forbidden resource, API Key has been deactivated.
  • LimitExceededRequestException: Too many requests in a short time.

Dependencies

http: ^0.13.1
intl: ^0.17.0

License

BSD 3-Clause License

Libraries

crime
Package to make Crime data requests, this api lets you retrieve crime information from 30+ cities across the US and LATAM. The api exposes four methods to retrieve raw crime date, crime statistics, crime coverage information and crime crowsourced data. [...]