NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

yarn add @hmscore/react-native-hms-location
yarn add @hmscore/react-native-hms-map

maven {url 'http://developer.huawei.com/repo/' }


import DeviceInfo from 'react-native-device-info';
import HMSMap, { HMSMarker, FillMode, Interpolator, RepeatMode} from "@hmscore/react-native-hms-map";
import HMSLocation from '@hmscore/react-native-hms-location';


let mapHuawei;

this.state = {
hasGms: null,
hasHms: null,
};

constructor(props) {
DeviceInfo.hasGms().then(status =>{
this.setState({
hasGms: status,
});
});
DeviceInfo.hasHms().then(status =>{
this.setState({
hasHms: status,
});
});
}


{(hasHms && !hasGms)?
(
<HMSMap
ref={(e) => {
mapHuawei = e;
}}
style={styles.map}
myLocationEnabled={false}
myLocationButtonEnabled={false}
compassEnabled={true}
scrollGesturesEnabled={true}
camera={{ target: { latitude: SAUDI_CENTER_LAT, longitude: SAUDI_CENTER_LNG }, zoom: 8, bearing: 50, tilt: 90 }}
onMapReady={() => this.animateToCurrentLocation()}
onMapClick={this.onMapTapped}
useAnimation={true}
animationDuration={2000}
markerClustering={true}
>
{Object.keys(selectedLocation).length > 0 && (
<HMSMarker
coordinate={{
latitude: selectedLocation.latitude,
longitude: selectedLocation.longitude,
}}
icon={{ hue: 0 }}
/>
)}
</HMSMap>
):(
<MapView>

</MapView>
)
}

setAnimationHuaweiMap = (latitude = 0.0, longitude= 0.0) => {
if(mapHuawei){
mapHuawei.setCameraPosition({ target: { latitude: latitude, longitude: longitude }, zoom: 13, tilt: 0, bearing: 0 });
// mapHuawei.setCoordinates({ latitude: latitude, longitude: longitude }, 12);
// mapHuawei.setAnimation(
// {
// translate: {
// latitude: latitude,
// longitude: longitude,
// duration: 1000,
// fillMode: FillMode.BACKWARDS,
// interpolator: Interpolator.BOUNCE,
// repeatCount: 3,
// },
// },
// { duration: 2000, repeatMode: RepeatMode.REVERSE }
// );
// mapHuawei.startAnimation();
}
}

setFetchingCurrentLocationWithDelay(isFetching = false, delay = 250) {
setTimeout(() => {
this.setState({
fetchingCurrentLocation: isFetching,
});
}, delay);
}


getCurrentUserLocationHuawei = async () => {

const {
storeUserLocation,
storeSelectedLocation,
fetchAddressFromCoordinates,
} = this.props;

this.setState({
fetchingCurrentLocation: true,
});

// Check location permissions
HMSLocation.FusedLocation.Native.hasPermission()
.then(result => {
let hasPermission = result.hasPermission === true;
if(hasPermission){
const locationRequest = {
id: "locationRequest" + Math.random() * 10000,
priority: HMSLocation.FusedLocation.PriorityConstants.PRIORITY_HIGH_ACCURACY,
interval: 5000,
numUpdates: 20,
fastestInterval: 6000,
expirationTime: 100000,
expirationTimeDuration: 100000,
smallestDisplacement: 0,
maxWaitTime: 1000.0,
needAddress: false,
language: "en",
countryCode: "en",
};

const locationSettingsRequest = {
locationRequests: [locationRequest],
alwaysShow: false,
needBle: false,
};

HMSLocation.FusedLocation.Native.checkLocationSettings(
locationSettingsRequest,
)
.then(res => {
console.log("locationSettings", res);
if ( res === true ||
(
res.locationSettingsStates.isGpsPresent == true
&&
res.locationSettingsStates.isGpsUsable == true
&&
res.locationSettingsStates.isLocationUsable == true
)
) {
HMSLocation.FusedLocation.Native.getLastLocation()
.then(position => {
console.log("Last Location:"+ JSON.stringify(position));

this.setAnimationHuaweiMap( position.latitude, position.longitude);

const coordinates = {
latitude: position.latitude,
longitude: position.longitude,
};
storeSelectedLocation && storeSelectedLocation(coordinates);
storeUserLocation && storeUserLocation(position);
fetchAddressFromCoordinates &&
fetchAddressFromCoordinates(position);
this.setFetchingCurrentLocationWithDelay();
})
.catch(err => {
console.log("Failed to get last location", err);
const LocationRequest = {
id: 'e0048e' + Math.random() * 10000,
priority: HMSLocation.FusedLocation.PriorityConstants.PRIORITY_HIGH_ACCURACY,
interval: 3,
numUpdates: 1,
fastestInterval: 1000.0,
expirationTime: 1000.0,
expirationTimeDuration: 1000.0,
smallestDisplacement: 0.0,
maxWaitTime: 1000.0,
needAddress: false,
language: 'en',
countryCode: 'en',
};

HMSLocation.FusedLocation.Native.requestLocationUpdatesWithCallback(
LocationRequest,
)
.then(({requestCode}) => {
console.log("id", requestCode);
})
.catch(ex =>
console.log("Exception while requestLocationUpdatesWithCallback " + ex),
);

HMSLocation.FusedLocation.Events.addFusedLocationEventListener(
location => {
console.log(location);
// setLocationCoordinates(location.hwLocationList[0]);
const position = location.hwLocationList[0];
this.setAnimationHuaweiMap( position.latitude, position.longitude);

const coordinates = {
latitude: position.latitude,
longitude: position.longitude,
};
storeSelectedLocation && storeSelectedLocation(coordinates);
storeUserLocation && storeUserLocation(position);
fetchAddressFromCoordinates &&
fetchAddressFromCoordinates(position);
this.setFetchingCurrentLocationWithDelay();
},
);

});
}
})
.catch(ex => {
console.log("Error while getting location settings. " + ex);
});
}

}).catch(ex =>{
console.log("Error while getting location permission info: " + ex);
}

);

}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.