在Iphone上实现令人惊艳的增强现实(AR)

原文地址

在Iphone上实现令人惊艳的增强现实(AR)

增强现实(AR)正是方兴未艾,在未来几年内将会成为手机上的软件标配。作者一步步教你如何在Iphone上实现增强现实(AR),虽然不能如口袋妖怪一样的复杂,但如果能在朋友聚会上秀一把,肯定能被赞为“大神”。

原文链接:https://medium.com/

抄录:

How to build an Augmented Reality App using the Foursquare API + Mapbox + ARKit

Gareth Paul Jones

Earlier this month, we saw this tweet from Aaron Ng showing how he used theMapbox Unity SDK, Apple’s ARKit, and Foursquare to visualize his check-ins on Foursquare. We wanted to break down the steps required for you to do this and turn more magic into reality for others.

This is a brief technical tutorial on building out a Foursquare powered Augmented Reality app using Unity w/the Mapbox Unity SDK, ARKit and Foursquare’s API. We’ll be building an iOS app displaying nearby coffee shops using Foursquare Venue Search.

Demo using Foursquare API, Mapbox Unity SDK and ARKit.

Note: At the time of writing, this project requires an iPhone 6S (or later) running a pre-release of iOS 11.3 w/Metal, a pre-release version of Xcode 9, and a patched version of Unity (Unity 5.6.1.p1 or later). Some experience with both Unity and iOS development is helpful, but not required.

Additionally we’ll continue to produce content as the Mapbox SDK evolves to support streaming map providers 😍.

Getting Started

Before getting started, you’ll need to:

Install Unity (Unity 5.6.1.p1 or later)

Create an empty Unity Project

Install, Configure and Setup the Mapbox Unity SDK.

Install the ARKit Plugin.

Step 1: Setup your environment

To get started, check out this guide to learn how to make a Unity scene with mesh terrain and Mapbox map imagery and the following to hotwire your app with ARKit.

As a reference point during the tutorial here is our Unity Scene Hierarchy

Further to this here is a breakdown of our GameObjects and details.

LocationProvider is shipped with the Mapbox Unity SDK

Map has three additional components (BuildMapAtLocation.cs, AbstractMap.cs, RangeTileProvider)

MainCamera has two additional components (UnityARVideo.cs, UnityARCameraManager.cs)

Player is added with PositionWithLocationManager.cs

Attribution provides attribution to Mapbox and Foursquare.

FoursquareFactory is added with FoursquareProvider.cs

Step 2: Setup the Foursquare API

In order to call the Foursquare API we can utilize UnityWebRequest to send a request to the Foursquare API and then use the built in JsonUtility to parse the response. We’ve chosen to keep this sample simple to find “coffee” utilizing our Venue Search API.

In the below we setup the function GetFoursquareVenueData to call the Foursquare API.

Once we do this we now need to parse the response with some models. In order to simplify things, we’ve included some sample models below. You can also utilize our extensive C-Sharp library too if preferred.

Now that we have our models setup we need to connect them to our GetFoursquareVenueData function.

Step 3: Create Foursquare Provider

In order to utilize the FoursquareAPI we plan to utilize Mapbox’s LocationProvider. This allows us to easily convert between the Unity World and Earth World (latitude and longitude). Additionally we could leverage the real-world location of the phone via LocationService.

We start by creating a GameObject named “FoursquareFactory” and attaching a “FoursquareProvider” which we will use as a function to display and surface Foursquare data.

Here you will need to add your CLIENT_ID and CLIENT_SECRET after signing up for a Foursquare Developer Account via developer.foursquare.com.

We can then call the function GetFoursquareVenueData inside our FoursquareProvider and create a Foursquare Map Object for venues near the phone.

Here is the final script for FoursquareProvider.

Finally let’s link everything together by creating a GameObject inside Unity with the name Player.

We then can attach the script PositionWithLocationProvider to this GameObject. We make some minor modifications here to allow us to push LocationData (lat,lng) over to the FoursquareProvider.

Step 4: Build and Deploy

You can now build your Unity Project and deploy this magic to your phone/tablet.

Given the complexity of all these steps, we’d encourage you to reach out to us @FoursquareAPI or via Stackoverflow for questions, tips and tricks.

A huge thank you to Mapbox, Unity and Apple for their efforts in this space, without their work these demos would not be possible.

At Foursquare, our mission is to make the world more delightful through location intelligence products including building illustrations like the one above. If this sounds like fun feel free to reach out and learn more.

Happy Building!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 202,009评论 5 474
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 84,808评论 2 378
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 148,891评论 0 335
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,283评论 1 272
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,285评论 5 363
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,409评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,809评论 3 393
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,487评论 0 256
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,680评论 1 295
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,499评论 2 318
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,548评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,268评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,815评论 3 304
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,872评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,102评论 1 258
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,683评论 2 348
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,253评论 2 341

推荐阅读更多精彩内容

  • 我准备去学车的时候,天还有点冷,在网上搜了很多家驾校,对比一番后,有家叫“雪宇”的驾校很吸引我,教练长得很帅,而且...
    素瓜豆阅读 237评论 0 0
  • 此文转载自:这篇博客 在Xcode中当你在更新了你得证书而再重新编译你的程序,真机调试会出现“Your build...
    xyzhao阅读 481评论 3 1
  • 元月8日–9日,“先锋引领.脱贫攻坚”2017南宁市产业扶贫龙头企业对接洽谈会,在南宁市委党校举行,姑娘江公司代表...
    姑娘江边的老九阅读 177评论 0 0