Coder Social home page Coder Social logo

mapsnearestneighbor's Introduction

MapsNearestNeighbor

Build Android Apps with google maps that calculate nearest coordinate (Android)

Getting Started

These app can calculate the nearest neighbor coordinate using euclidian distance equation, given some coordinate in ArrayList then system will calculate distance each coordinate with current location. in this project there is 4 main class:

  • Coordinates (Object Class for coordinates with its attributes: place, latitude, longitude)
  • Distances (Object Class for distances with its attributes: name, distances)
  • DummyActivity (tha main activity)
  • DummyCoordinates (contain some main method to calculate distance, calculate nearest distance, add market, etc)

Code

make sure you connect your project to google Maps in console.developers.google.com add your google maps key on res/values/google_maps_api.xml

method getDistances to calculate the distance between current location coordinate and coordinate A using Euclidian Distance equation

private static ArrayList<Distances> getDistance(double cuLat, double curLong, ArrayList<Coordinates> coord) {
    ArrayList<Distances> distances = new ArrayList<>();
    for (int i=0;i<coord.size();i++){
        distances.add(new Distances(coord.get(i).getPlace(),(Math.sqrt((coord.get(i).getLatitude() - cuLat) * (coord.get(i).getLatitude() - cuLat) + (coord.get(i).getLongitude() - curLong) * (coord.get(i).getLongitude() - curLong)))));
    }
    return distances;
}

method getNearestDistance to calculate the nearest distance between current location coordinate and other coordinate B by comparing distance and pick the smallest one.

private static Distances getNearestDistance(double curLat, double curLong, ArrayList<Coordinates> coord) {
    ArrayList<Distances>distances = getDistance(curLat, curLong, coord);
    Distances nearest = new Distances("",Double.MAX_VALUE);
    for(int i=0;i<distances.size();i++) {
        if (nearest.getDistances() > distances.get(i).getDistances()) {
            nearest.setDistances(distances.get(i).getDistances());
            nearest.setName(distances.get(i).getName());
        }
    }
    return nearest;
}

Built With

  • IDE - Android Studio 2.1.3
  • Operating System - Ubuntu

Authors

  • Marchellin Antonia

Screenshot

  • first action is locate current location


* when nearby coordinate button is clicked, it show all coordinates in ArrayList and mark the nearest one with blue marker

mapsnearestneighbor's People

Contributors

marchellinantonia avatar

Watchers

 avatar

mapsnearestneighbor's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.