当前位置:网站首页>Arfoundation starts from scratch 8-geospatial API (geospatial) development
Arfoundation starts from scratch 8-geospatial API (geospatial) development
2022-07-29 05:16:00 【suelee_ hm】
ARCore Geospatial API For developers Live View Underlying technology , Including large-scale cloud anchor function , And global visual positioning system (VPS) Access rights of , Can be used to develop multi person shared AR application .
The technology is based on Google Earth 3D Model data and street view image data , The principle is to convert tens of billions of street view images into support VPS Positioning of the 3D Point cloud , A total of trillions of 3D data . In less than a second , According to 3D Location of point cloud data positioning equipment And direction .
Project sample source code :
https://github.com/sueleeyu/ar-geospatial
One 、 Create project engineering and installation ARCore Extensions software package
See :
https://blog.csdn.net/weixin_40239288/article/details/125328974
Two 、 Set up google cloud project
Use a visual positioning system (VPS), You need to associate a Google Cloud project , And in time Google Cloud In the project Enable ARCore API, newly build Google Cloud project :
1. visit :https://console.cloud.google.com/projectcreate, New projects .
2. Click create to create a new one :

3. Select... From the sidebar menu API And the service - library :

4. Input ARCore API And search for

5. Click Select ARCore API

6. Click enable

7. Enter the following page

3、 ... and 、 Set authorization
After the application needs authorization , To call Geospatial API, Whether the authorization has key authorization and API Key authorization , It is recommended to use keyless authorization .
Realization API Key authorization :
1. go to Cloud Console Medium API And the service → The credentials panel , choice Create credentials , Then select from the drop-down menu API secret key :

Copy the key after creation :

Copy the key
2. stay Unity in , go to Edit > Project Settings > XR > ARCore Extensions. Android Authentiation Strategy Drop down menu , choice API Key

3. stay Android API Key Field , Paste from Google Cloud Platform To obtain the API secret key , And check the Optional Features The next two are to be used API Check box :

Authorization complete . Next, enable Geospatial API.
Four 、 Enable Geospatial API
1.Assets Choose ARCoreExtensionsConfig Script object , And then in Inspector Window , The drop-down Geospatial Mode choice Enabled.

5、 ... and 、 Write a script
1. mount AREarth Manager, choice Hierarchy-AR Session Origin-Add Component-AR Earth Manager:

2.Hierarchy-‘+’-Create Empty, Name it GeospatialController;Assets-Scripts Right click New GeospatialController.cs, Drag to GeospatialController object :


To obtain position :
The main functions are update() To realize :
1. Judge and check equipment compatibility , call :
EarthManager.IsGeospatialModeSupported(GeospatialMode.Enabled);
Need to return FeatureSupported.Supported Only then can .
2. Check the tracking status
var earthTrackingState = EarthManager.EarthTrackingState;
Only when the earthTrackingState==rackingState.Tracking when , Geospatial values are valid . As shown below :
var earthTrackingState = EarthManager.EarthTrackingState;
if (earthTrackingState == TrackingState.Tracking)
{
// Values obtained by the Geospatial API are valid as long as
// earthTrackingState is TrackingState.Tracking.
// Use Geospatial APIs in this block.
}
3. Get camera geospatial pose .REarthManager Manage camera geospatial posture , When TrackingState by Tracking when , request Camera position and direction relative to the earth :
var earthTrackingState = EarthManager.EarthTrackingState;
if (earthTrackingState == TrackingState.Tracking)
{
// camera_geospatial_pose contains geodetic location, rotation, and
// confidences values.
var cameraGeospatialPose = EarthManager.CameraGeospatialPose;
}
cameraGeospatialPose It contains the information of geospatial posture :
a. Position in latitude and longitude . Besides , It also provides an estimate of the accuracy of the location information .
b. At an altitude of , And the estimation of altitude .
c. Direction 、 Approximate value of the direction the device is facing , And an estimate of the accuracy of the course .
Place geospatial anchors :
Use ARAnchorManagerExtensions in ARAnchorManager.AddAnchor establish ARGeospatialAnchor, To anchor the content to the specified geographic coordinates .
When positioning the anchor point relative to the position and direction of the earth , Latitude and longitude are determined by WGS84 standard Definition , The altitude value is determined by WGS84 The height of the ellipsoid ( In meters ) Definition . Identity rotation takes place with the anchor facing , send X+ Point East ,Y+ Point up , Away from the center of the earth ,Z+ Point south .
private bool PlaceGeospatialAnchor(GeospatialAnchorHistory history)
{
Quaternion quaternion =
Quaternion.AngleAxis(180f - (float)history.Heading, Vector3.up);
var anchor = AnchorManager.AddAnchor(
history.Latitude, history.Longitude, history.Altitude, quaternion);
if (anchor != null)
{
GameObject anchorGO = Instantiate(GeospatialPrefab, anchor.transform);
_anchorObjects.Add(anchorGO);
return true;
}
return false;
}
Be careful : It is not supported in the north pole or the South Pole (90 Degree or -90 degree ) Create anchors inside . If you try to use such anchors ,AnchorManager.AddAnchor Returns the null.
Calculate the altitude [Geospatial file ]:
Getting the altitude at which the anchor is placed is a bit tricky . You must compare the altitude of the equipment location with Geospatial API Compare the altitude of . There are two ways to determine the altitude :
If the location of the anchor point is close to the user , Please consider using an altitude similar to the altitude of the equipment .
otherwise , Please consider starting from Google Get the altitude value from the height of the map .
Using the camera GeospatialPose The altitude of
You may only need to use from AREarthManager.CameraGeospatialPose Obtained altitude , Without cross checking from other sources ( Such as Maps API) The data of , Maybe enough . See above Get the camera geospatial position and direction .
If you can get the position posture in advance by observing the local position by yourself , You can use this data to cross check the GeospatialPose.
from Google Map the altitude
GeospatialPose For reporting WGS84 The altitude above the ellipsoid ( In meters ). Your application needs to GeospatialPose.Altitude The value of is compared with the altitude of the equipment location , To determine the exact altitude of the anchor .
You can use Google Map Get latitude and longitude . Please be sure to close first “ Earth view ”, The method is to navigate to the layer > more , Then uncheck the earth view check box in the lower left corner of the screen . This will be enforced 2D visual angle , And eliminate the angle 3D Possible errors caused by view .
After determining latitude and longitude , Please use Elevation API according to EGM96 Specification acquisition height . You must put the Maps API EGM96 Altitude is converted to WGS84, Talent and GeospatialPose Compare the altitude . See include both command line and HTML Interface GeoidEval Transformation tool .Maps API Use it out of the box WGS84 The specification reports latitude and longitude .
6、 ... and 、UI And interface
1. establish ARView Panel, Click on ‘+’-UI-Panel, Name it ARView,remove component Image and Canvas Renderer


2.ARView Next right click New InfoPanel

Set the properties as follows :

3.InfoPanel Under the new Text, name InfoText, Set up :

4.ARView Under the new Panel, name SnackBar, Set up :

5.SnackBar Under the new Text, name DebugText, Set up :


6.SnackBar Under the new Text, name SnackBarText, Set up :


7. SnackBar Under the new Button, name SetAnchorButton, Set up :

SetAnchorButton-Text:

8. SnackBar Under the new Button, name ClearAllButton, Set up :

ClearAllButton-Text:

9.Canvas Right click -UI-Panel, name PrivacyPrompt,PrivacyPrompt Next right click New Panel, name FullscreenBackground, Set up :

10. PrivacyPrompt Next right click New Panel, name PrivacyContent, Set up :

PrivacyContent Under the new Panel, name PrivacyPromptBackground, Set up :

PrivacyContent Under the new Panel, name Information Panel, Set up :

11. Information Panel Under the new Text, name Title Text, Set up :

Information Panel Under the new Panel, name Text Area, Set up :

Text Area Under the new Text, name Information Text, Set up :

Information Text Under the new Button, name URL Button, Delete URL Button Next Text, Set up :

Start Button Set up click event , call GeospatialController. OnLearnMoreClicked ():

Information Panel Under the new Button, name Start Button, Set up :

Start Button Set up click event , call GeospatialController. OnGetStartedClicked():

7、 ... and 、 Packaging operation


7、 ... and 、 common problem
1. Use ARCore Extension API Example program :Window-Package Manager-ARCore Extensions-Samples, Click on Import Button to import the sample code to be used .

2. error CS0234: Namespace “UnityEditor” Type or namespace name... Does not exist in “iOS”:
solve : install UnitySetup-iOS-Support-for-Editor-2020.2.6f1.
8、 ... and 、 reference
1. Unity api:
Unity - Manual: Unity User Manual 2021.3 (LTS)
2. Geospatial file :
Use ARCore Geospatial API Create a global scale immersive AR Experience | Google Developers
3.Google AR:
https://github.com/google-ar
https://github.com/google-ar/arcore-unity-extensions
4. The sample source code of this project :
边栏推荐
- 时间序列分析的表示学习时代来了?
- P2181 diagonal
- ARFoundation入门教程10-平面检测和放置
- 源码编译pytorch坑
- How does excel filter out the content you want? Excel table filtering content tutorial
- Let you understand several common traffic exposure schemes in kubernetes cluster
- AUTOSAR from introduction to proficiency 100 lectures (78) -autosar-dem module
- Apache POI implements excel import, read data, write data and export
- The song of the virtual idol was originally generated in this way!
- Excel怎么筛选出自己想要的内容?excel表格筛选内容教程
猜你喜欢

ARFoundation从零开始3-创建ARFoundation项目

js(forEach)出现return无法结束函数的解决方法

三层项目的架构分析及构造方法的参数名称注入

A little knowledge about management

Mysql多对多关系,分组拼接把多个数据查询到一条数据上

Jackson parsing JSON detailed tutorial

< El table column> place multiple pictures

基于注解的三层项目的改造及添加包扫描的方式

How to add traffic statistics codes to the legendary Development Zone website

Learn the first program of database
随机推荐
About realizing page Jump of website in Servlet
【2022新生学习】第三周要点
Reply from the Secretary of jindawei: the company is optimistic about the market prospect of NMN products and has launched a series of products
Operator operation list of spark
How to install Office2010 installation package? How to install Office2010 installation package on computer
Open the tutorial of adding and modifying automatically playing music on the open zone website
Excel怎么筛选出自己想要的内容?excel表格筛选内容教程
网安学习-内网安全1
Young freshmen yearn for more open source | here comes the escape guide from open source to employment!
Let you understand several common traffic exposure schemes in kubernetes cluster
The song of the virtual idol was originally generated in this way!
Rolabelimg to data format data
How to monitor micro web services
怎样监测微型的网站服务
ARFoundation从零开始5-AR图像跟踪
Google gtest事件机制
Button for QT custom switch effect
【config】配置数组参数
JS daily question (12)
AttributeError: ‘module‘ object has no attribute ‘create_connection‘