splicer97 / react-native-osmdroid Goto Github PK
View Code? Open in Web Editor NEWReact Native wrapper for osmdroid maps
License: MIT License
React Native wrapper for osmdroid maps
License: MIT License
this is my App component:
import MapView, { UrlTile } from '@splicer97/react-native-osmdroid';
import React, { useEffect } from 'react';
import { PermissionsAndroid, View } from 'react-native';
import ReactNativeFileStream from 'react-native-fs';
const App = () => {
useEffect(() => {
requestPermission();
checkIsExistTile();
},
[])
const uri = `file://${ReactNativeFileStream.DownloadDirectoryPath}/Tiles/0/0/0.png`;
console.log(uri) // file:///storage/emulated/0/Download/Tiles/0/0/0.png
const checkIsExistTile = async () => {
const isExist = await ReactNativeFileStream.exists(`file://${ReactNativeFileStream.DownloadDirectoryPath}/Tiles/0/0/0.png`)
console.log(isExist)
}
const requestPermission = async () => {
const WRITE_EXTERNAL_STORAGE = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
{
title: 'Permission',
message: 'Message',
buttonNeutral: 'Ask Me Later',
buttonNegative: 'Cancel',
buttonPositive: 'OK',
},
);
console.log(WRITE_EXTERNAL_STORAGE === PermissionsAndroid.RESULTS.GRANTED)
const READ_EXTERNAL_STORAGE = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE,
{
title: 'Permission',
message: 'Message',
buttonNeutral: 'Ask Me Later',
buttonNegative: 'Cancel',
buttonPositive: 'OK',
},
);
console.log(READ_EXTERNAL_STORAGE === PermissionsAndroid.RESULTS.GRANTED)
const ACCESS_FINE_LOCATION = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
{
title: 'Permission',
message: 'Message',
buttonNeutral: 'Ask Me Later',
buttonNegative: 'Cancel',
buttonPositive: 'OK',
},
);
console.log(ACCESS_FINE_LOCATION === PermissionsAndroid.RESULTS.GRANTED)
}
return (
<View style={{ flex: 1 }}>
<MapView style={{ width: "100%", height: "100%" }}
initialRegion={{ latitude: 29.5918, longitude: 52.5837, latitudeDelta: 0.0922, longitudeDelta: 0.0421 }}>
<UrlTile urlTemplate={`file://${ReactNativeFileStream.DownloadDirectoryPath}/Tiles/{z}/{x}/{y}.png`} />
</MapView>
{/* to approve that tile is exit */}
{/* <Image source={{ uri }} style={{ width: 500, height: 500 }} /> */}
</View>
)
}
export default App;
my package.json:
{
"name": "maposmdroid",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"lint": "eslint .",
"start": "react-native start",
"test": "jest"
},
"dependencies": {
"@splicer97/react-native-osmdroid": "^0.14.0",
"react": "18.2.0",
"react-native": "0.73.1",
"react-native-fs": "^2.19.0"
},
"devDependencies": {
"@babel/core": "^7.20.0",
"@babel/preset-env": "^7.20.0",
"@babel/runtime": "^7.20.0",
"@react-native/babel-preset": "^0.73.18",
"@react-native/eslint-config": "^0.73.1",
"@react-native/metro-config": "^0.73.2",
"@react-native/typescript-config": "^0.73.1",
"@types/react": "^18.2.6",
"@types/react-test-renderer": "^18.0.0",
"babel-jest": "^29.6.3",
"eslint": "^8.19.0",
"jest": "^29.6.3",
"prettier": "2.8.8",
"react-test-renderer": "18.2.0",
"typescript": "5.0.4"
},
"engines": {
"node": ">=18"
}
}
I copied those tiles in the download folder:
And:
My AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
why it does not show tiles?
Hey,
I have trouble to get an Google Maps Key, and I don't really need gmaps.
I've found your module and thought great... but now I get this Errror:
react-native-osmdroid doesn't support android
I was using Expo SDK 44 and older react native, because I have trouble to compile higher Versions due to dependencies missmatch. Compiled Version with SDK was working but crashes when opening original Map View because no API Key is set. Even with WMTS Maps.. great. (So It's not crashing generally)
What ever, I've upgraded to newest Expo SDK 48 and react-native 0.71.6 (since ur using above 0.70 and i was using below)
I still get the Error when I open the Map Component.
Is the Component not compatible with expo? The Base was I guess
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.