├── .gitignore ├── public ├── images │ ├── OG.png │ └── PinClipart.com_recreational-vehicle-clip-art_3227183.png └── main.css ├── src ├── routes │ ├── province.js │ ├── district.js │ └── city.js └── schema │ ├── Districts.js │ ├── Province.js │ └── City.js ├── package.json ├── LICENSE ├── index.js ├── views └── index.ejs └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | #node_modules 2 | .DS_Store 3 | node_modules 4 | 5 | #env 6 | .env -------------------------------------------------------------------------------- /public/images/OG.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PasinduS96/location-api-sl/HEAD/public/images/OG.png -------------------------------------------------------------------------------- /public/images/PinClipart.com_recreational-vehicle-clip-art_3227183.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PasinduS96/location-api-sl/HEAD/public/images/PinClipart.com_recreational-vehicle-clip-art_3227183.png -------------------------------------------------------------------------------- /public/main.css: -------------------------------------------------------------------------------- 1 | html, 2 | body { 3 | margin: 0; 4 | padding: 0; 5 | width: 100%; 6 | height: 100%; 7 | display: table; 8 | } 9 | .content { 10 | display: table-cell; 11 | text-align: center; 12 | vertical-align: middle; 13 | } 14 | 15 | .text-main { 16 | font-family: 'Raleway', sans-serif; 17 | font-size: larger; 18 | } 19 | 20 | .styled-text { 21 | font-family: 'Raleway', sans-serif; 22 | } 23 | -------------------------------------------------------------------------------- /src/routes/province.js: -------------------------------------------------------------------------------- 1 | const mongoose = require('mongoose'); 2 | const express = require('express'); 3 | const router = express.Router(); 4 | 5 | require('../schema/Province') 6 | const province = mongoose.model('provinces'); 7 | 8 | router.get('/', (req,res) => { 9 | province.find().then(result => { 10 | res.send(result); 11 | }).catch(err =>{ 12 | console.log(err); 13 | }) 14 | }) 15 | 16 | module.exports = router; -------------------------------------------------------------------------------- /src/schema/Districts.js: -------------------------------------------------------------------------------- 1 | const mongoose = require('mongoose'); 2 | 3 | const DistrictSchema = mongoose.Schema({ 4 | id: { 5 | type: Number, 6 | required: true 7 | }, 8 | province_id: { 9 | type: Number, 10 | required: true 11 | }, 12 | name_en: { 13 | type: String, 14 | required: true 15 | }, 16 | name_si: { 17 | type: String, 18 | required: true 19 | }, 20 | name_ta: { 21 | type: String, 22 | required: true 23 | } 24 | }) 25 | 26 | mongoose.model('districts', DistrictSchema); -------------------------------------------------------------------------------- /src/schema/Province.js: -------------------------------------------------------------------------------- 1 | const mongoose = require('mongoose'); 2 | 3 | const ProvinceSchema = mongoose.Schema({ 4 | id: { 5 | type: Number, 6 | required: true 7 | }, 8 | province_id: { 9 | type: Number, 10 | required: true 11 | }, 12 | name_en: { 13 | type: String, 14 | required: true 15 | }, 16 | name_si: { 17 | type: String, 18 | required: true 19 | }, 20 | name_ta: { 21 | type: String, 22 | required: true 23 | } 24 | }) 25 | 26 | mongoose.model('provinces', ProvinceSchema); -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "location_api", 3 | "version": "1.0.0", 4 | "description": "This API can be use to all developers to get location details of Sri Lanka including major cities, sub areas, districts and Provinces", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "start": "nodemon app.js" 9 | }, 10 | "author": "Pasindu Senarathne", 11 | "license": "MIT", 12 | "dependencies": { 13 | "body-parser": "^1.19.0", 14 | "cors": "^2.8.5", 15 | "dotenv": "^10.0.0", 16 | "ejs": "^3.1.6", 17 | "express": "^4.17.1", 18 | "express-ejs-layouts": "^2.5.0", 19 | "mongoose": "^5.12.12", 20 | "nodemon": "^2.0.7" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/routes/district.js: -------------------------------------------------------------------------------- 1 | const mongoose = require('mongoose'); 2 | const express = require('express'); 3 | const router = express.Router(); 4 | 5 | require('../schema/Districts') 6 | const districts = mongoose.model('districts'); 7 | 8 | router.get('/', (req,res) => { 9 | districts.find().then(result => { 10 | res.send(result); 11 | }).catch(err =>{ 12 | console.log(err); 13 | }) 14 | }) 15 | 16 | router.get('/byprovince/:id', (req,res) => { 17 | districts.find({province_id: req.params.id},{ name_en: 1, name_si: 1, name_ta:1 }).then(result => { 18 | res.send(result); 19 | }).catch(err =>{ 20 | console.log(err); 21 | }) 22 | }) 23 | 24 | router.get('/districtcount/:id', (req,res) => { 25 | districts.countDocuments({province_id: req.params.id}).then(result => { 26 | res.status(200).send({count: result});; 27 | }).catch(err =>{ 28 | console.log(err); 29 | }) 30 | }) 31 | 32 | 33 | 34 | 35 | module.exports = router; -------------------------------------------------------------------------------- /src/schema/City.js: -------------------------------------------------------------------------------- 1 | const mongoose = require('mongoose'); 2 | 3 | const CitySchema = mongoose.Schema({ 4 | district_id: { 5 | type: Number, 6 | required: true 7 | }, 8 | name_en: { 9 | type: String, 10 | required: true 11 | }, 12 | name_si: { 13 | type: String, 14 | required: true 15 | }, 16 | name_ta: { 17 | type: String, 18 | required: true 19 | }, 20 | sub_name_en: { 21 | type: String, 22 | required: true 23 | }, 24 | sub_name_si: { 25 | type: String, 26 | required: true 27 | }, 28 | sub_name_ta: { 29 | type: String, 30 | required: true 31 | }, 32 | postcode: { 33 | type: String, 34 | required: true 35 | }, 36 | latitude: { 37 | type: String, 38 | required: true 39 | }, 40 | longitude: { 41 | type: String, 42 | required: true 43 | }, 44 | }) 45 | 46 | mongoose.model('cities', CitySchema); -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Pasindu Senarathne 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const app = express(); 3 | const mongoose = require('mongoose'); 4 | const bodyParser = require('body-parser'); 5 | const cors = require('cors'); 6 | 7 | const cities = require('./src/routes/city'); 8 | const districts = require('./src/routes/district'); 9 | const provinces = require('./src/routes/province'); 10 | 11 | require("dotenv").config(); 12 | 13 | app.use(bodyParser.urlencoded({extended: false})) 14 | app.use(bodyParser.json()); 15 | 16 | app.use(express.static('public')) 17 | 18 | app.use(cors()) 19 | 20 | app.set('view engine', 'ejs') 21 | 22 | app.listen(process.env.PORT, () =>{ 23 | 24 | console.log(`server started at ${process.env.PORT}`); 25 | 26 | //Connect to the database 27 | mongoose.Promise = global.Promise; 28 | mongoose 29 | .connect(process.env.MONGO_URI,{ 30 | useFindAndModify: false, 31 | useNewUrlParser: true, 32 | useUnifiedTopology: true 33 | }, (err, db) =>{ 34 | if(!err){ 35 | console.log("MongoDB Connected Successfully!!") 36 | }else{ 37 | console.log(err); 38 | } 39 | }) 40 | }) 41 | 42 | app.get('/', (req,res) => { 43 | res.render('index') 44 | }) 45 | 46 | app.use('/cities', cities) 47 | app.use('/districts', districts) 48 | app.use('/provinces', provinces) -------------------------------------------------------------------------------- /src/routes/city.js: -------------------------------------------------------------------------------- 1 | const mongoose = require('mongoose'); 2 | const express = require('express'); 3 | const router = express.Router(); 4 | 5 | require('../schema/City') 6 | const city = mongoose.model('cities'); 7 | 8 | router.get('/', (req,res) => { 9 | city.find().then(result => { 10 | res.send(result); 11 | }).catch(err =>{ 12 | console.log(err); 13 | }) 14 | }) 15 | 16 | router.get('/cordinates/:city', (req,res) => { 17 | city.find({name_en: req.params.city},{ name_en: 1,latitude: 1, longitude: 1, _id: 0 }).then(result => { 18 | res.send(result); 19 | }).catch(err =>{ 20 | console.log(err); 21 | }) 22 | }) 23 | 24 | router.get('/byDistrict/:id', (req,res) => { 25 | city.find({district_id: req.params.id}).then(result => { 26 | res.send(result); 27 | }).catch(err =>{ 28 | console.log(err); 29 | }) 30 | }) 31 | 32 | router.get('/colombo_mca/:id', (req,res) => { 33 | city.find({name_en: "Colombo "+ req.params.id}).then(result => { 34 | res.send(result); 35 | }).catch(err =>{ 36 | console.log(err); 37 | }) 38 | }) 39 | 40 | router.get('/colombo_mca', (req,res) => { 41 | city.find({name_en: /Colombo/}).then(result => { 42 | res.send(result); 43 | }).catch(err =>{ 44 | console.log(err); 45 | }) 46 | }) 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | module.exports = router; -------------------------------------------------------------------------------- /views/index.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | LocateSriLanka 44 | 45 | 49 | 50 | 51 | 52 | 53 | 54 |
55 |
56 | img 60 |
61 |
62 |

Integrate Locations, All Around The Sri Lanka Easily To Your App

63 |
You can use Sri Lanka Location API to your applications for free and it enable to access location data through simple URLs
64 |
65 |
66 | API Documantation 67 | View Repository 68 |
69 |
70 | 71 | 12 | Table of Contents 13 |
    14 |
  1. 15 | Introduction 16 |
  2. 17 |
  3. 18 | Technologies 19 | 23 |
  4. 24 |
  5. 25 | Use Cases 26 |
  6. 27 |
  7. Getting Started
  8. 28 |
  9. Project Setup
  10. 29 |
  11. Contributing
  12. 30 |
  13. Acknowledgements
  14. 31 |
32 | 33 | 34 | 35 | ## Introduction 36 | 37 | Developers can use this API to get datails of cities, districts and provinces which located all around the Sri Lanka. This API can easily intergarte to you appication using particular URI. 38 | 39 | 40 | ## Technologies 41 | 42 | ### Implemantations 43 | 44 | - MongoDB 45 | - NodeJS 46 | 47 | ### Hosting 48 | 49 | - Heroku 50 | - DigitalOcean 51 | 52 | 53 | ## Use Cases 54 | 55 | - Developers can get **major cities and sub areas** in each district 56 | - **GPS cordinates** (Latitude and Longitude) are avilabe for each major city and sub areas. GPS cordinates can be use with Google Maps and other GPS/ Map services 57 | - Developers can easily get **Administrative Districts of the Colombo Mucipal Council** with GPS cordinates, Administrative Distict Name and Sub Area (Known name like Kollupitiya, Modara, etc.) 58 | - Users can get all the disticts and provinces in Sri Lanka 59 | 60 | 61 | ## Getting Started 62 | 63 | ### API Documentation 64 | 65 | #### 1. Get Major Cities And Sub Areas in Sri Lanka 66 | 67 | ```sh 68 | https://locatesrilanka.herokuapp.com/cities 69 | ``` 70 | 71 | #### 2. Get All Provinces in Sri Lanka 72 | 73 | ```sh 74 | https://locatesrilanka.herokuapp.com/provinces 75 | ``` 76 | 77 | #### 3. Get All Districts in Sri Lanka 78 | 79 | ```sh 80 | https://locatesrilanka.herokuapp.com/districts 81 | ``` 82 | 83 | #### 4. Get GPS Cordinates of major city or sub area in Sri Lanka 84 | 85 | ```sh 86 | https://locatesrilanka.herokuapp.com/cities/cordinates/[CITY NAME IN ENGLISH] 87 | ``` 88 | ###### Example 89 | 90 | Assume user needs to find GPS cordinates of Kadduwela, Sri Lanka 91 | 92 | 93 | ```sh 94 | https://locatesrilanka.herokuapp.com/cities/cordinates/Kaduwela 95 | ``` 96 | 97 | #### 5. Get all major cities or sub areas in selected distict Sri Lanka 98 | 99 | ```sh 100 | https://locatesrilanka.herokuapp.com/cities/cordinates/[DISTRICT ID] 101 | ``` 102 | ###### Example 103 | 104 | Assume user needs to find GPS cordinates of Colombo District, Sri Lanka 105 | 106 | 107 | ```sh 108 | https://locatesrilanka.herokuapp.com/cities/byDistrict/5 109 | ``` 110 | 111 | #### 6. Get Administrative Districts of the Colombo Mucipal Council, Sri Lanka 112 | 113 | ```sh 114 | https://locatesrilanka.herokuapp.com/cities/colombo_mca/[COLOMBO SUB AREA] 115 | ``` 116 | ###### Example 117 | 118 | Assume user needs to find details of Colombo 1, Sri Lanka 119 | 120 | 121 | ```sh 122 | https://locatesrilanka.herokuapp.com/cities/colombo_mca/1 123 | ``` 124 | 125 | 126 | #### 7. Get all Administrative Districts of the Colombo Mucipal Council, Sri Lanka 127 | 128 | ```sh 129 | https://locatesrilanka.herokuapp.com/cities/colombo_mca 130 | ``` 131 | 132 | 133 | #### 8. Get all Districts in Selected Province 134 | 135 | ```sh 136 | https://locatesrilanka.herokuapp.com/districts/byprovince/[PROVINCE ID] 137 | ``` 138 | ###### Example 139 | 140 | Assume user needs to find districts in western province, Sri Lanka 141 | 142 | 143 | ```sh 144 | https://locatesrilanka.herokuapp.com/districts/byprovince/1 145 | ``` 146 | 147 | #### 9. Get count of all Districts in Selected Province 148 | 149 | ```sh 150 | https://locatesrilanka.herokuapp.com/districts/districtcount/[PROVINCE ID] 151 | ``` 152 | ###### Example 153 | 154 | Assume user needs to find count of districts in western province, Sri Lanka 155 | 156 | 157 | ```sh 158 | https://locatesrilanka.herokuapp.com/districts/districtcount/1 159 | ``` 160 | 161 | 162 | ### Project Setup 163 | 164 | 1. Clone the repo 165 | ```sh 166 | git clone https://github.com/PasinduS96/location-api-sl.git 167 | ``` 168 | 2. Install NPM packages 169 | ```sh 170 | npm install 171 | ``` 172 | 3. Create .env file for environment varialbes 173 | 4. Create environment variables 174 | ```sh 175 | PORT= 176 | MONGO_URI= 177 | ``` 178 | 5. Run Project 179 | ```sh 180 | npm start 181 | ``` 182 | 183 | ## Contributing 184 | 185 | Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**. 186 | 187 | 1. Fork the Project 188 | 2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`) 189 | 3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`) 190 | 4. Push to the Branch (`git push origin feature/AmazingFeature`) 191 | 5. Open a Pull Request 192 | 193 | 194 | ## Acknowledgements 195 | * [Sri Lanka Provinces Districts Cities Database](https://github.com/madurapa/sri-lanka-provinces-districts-cities) 196 | 197 | [license-shield]: https://img.shields.io/github/license/PasinduS96/location-api-sl?style=for-the-badge 198 | [license-url]: https://github.com/PasinduS96/location-api-sl/blob/master/LICENSE 199 | [forks-shield]: https://img.shields.io/github/forks/PasinduS96/location-api-sl?style=for-the-badge 200 | [forks-url]: https://github.com/PasinduS96/location-api-sl/network/members 201 | [stars-shield]: https://img.shields.io/github/stars/PasinduS96/location-api-sl?style=for-the-badge 202 | [stars-url]: https://github.com/PasinduS96/location-api-sl/stargaze 203 | 204 | ## License 205 | 206 | MIT © [PasinduS96](https://github.com/PasinduS96/location-api-sl/blob/master/LICENSE) 207 | --------------------------------------------------------------------------------