react-map-location
Version:
provide simple location based features
130 lines (81 loc) • 3.27 kB
Markdown
`npm install react-map-location`
`yarn add react-map-location`
1. To find current position latitude and longitude.
2. To know information about your city with city name.
3. To know information of given location using latitude and longitude.
4. Weather information of your city.
5. Know weather information base on latitude and longitude.
Using this function you find your current position.
This function return object with latitude and longitude attributes.
```javascript
import { CurrentLocation } from "react-map-location";
const { latitude, longitude } = CurrentLocation();
```
This function take two argument which is name of city and your api key.
It returns information of city like lat,long,city,state,country, postal code.
```javascript
import { CityInfo } from "react-map-location";
const cityInfo = CityInfo({CITY_NAME},{YOUR_API_KEY});
```
This function contain 3 argument 1.latitude, 2.longitude , 3.api key as attribute.
This function returns information about city name, country,state,postal code.
```javascript
import { LocationInfo } from "react-map-location";
const locationTnfo = LocationInfo({LATITUDE}, {LONGITUDE},{YOUR_API_KEY});
```
This function take two argument as attribute 1.city name & 2.api key.
It is return the weather information of city like
temperature : min_temp, max_temp
Wind : direction, speed , description
Sun moon position : sunrise , sunset
Pressure , humidity etc.
```javascript
import { CityWeather } from "react-map-location";
const cityWeather = CityWeather({CITY_NAME},{YOUR_API_KEY});
```
This function take 1.langitude , 2.latitude & 3.api key as an attributes and return weather information.
```javascript
import { LocationWeather } from "react-map-location";
const locationWeather = LocationWeather({LATITUDE}, {LONGITUDE},{YOUR_API_KEY});
```
You have to your own here API key
generate your own api key by create project on [here platform](https://developer.here.com/)
Here replace {CITY_NAME},{LATITUDE},{LONGITUDE} AND {YOUR_API_KEY} with your own data.
```javascript
import React from 'react';
import ReactDOM from 'react-dom';
import { CurrentLocation, CityInfo, LocationInfo, CityWeather, LocationWeather} from "react-map-location";
const = App() => {
//object destructuring of CurrentLocation functin's return object
const { latitude, longitude } = CurrentLocation();
const cityInfo = CityInfo({CITY_NAME},{YOUR_API_KEY});
const locationTnfo = LocationInfo({LATITUDE}, {LONGITUDE},{YOUR_API_KEY});
const cityWeather = CityWeather({CITY_NAME},{YOUR_API_KEY});
const locationWeather = LocationWeather({LATITUDE}, {LONGITUDE},{YOUR_API_KEY});
console.log(latitude);
console.log(longitude);
console.log(cityInfo);
console.log(locationTnfo);
console.log(cityWeather);
console.log(locationWeather);
}
ReactDOM.render(
<>
<App />
</>,
document.getElementById('root')
);
```