Find Place Address Using Location Coordinates

Ufinix Academy
A free video tutorial from Ufinix Academy
Learn programming and app development
4.4 instructor rating • 4 courses • 2,269 students

Learn more from the full course

Xamarin Android Uber Clone App with C# and Firebase

Learn advanced Xamarin Android concepts by building a fully complete and functional Uber Clone app using Firebase

15:26:55 of on-demand video • Updated July 2020

  • Learn to build complete Uber Clone apps (driver and passenger) with C#, Xamarin and Firebase
  • Learn to create, remove, update and delete records in Firebase Database
  • Save and handle data locally using Shared Preferences
  • Learn how to use Google Location and Map services in your Apps
  • Learn to find direction from one point to the other with Google Direction Api
  • Learn to find place address with Location Coordinates using Google Geocoding API
  • Learn advanced usage of C# Lambda Expressions
  • Learn advanced usage and creation of custom C# Event handlers
  • Learn to create and design beautiful User Interfaces
  • Understand how to create Local Notifications using Android Notification Manager
  • Learn to make asynchronous WebCallls using Rest Api
  • Learn to initiate a phone call from your app using Native Intents
English [Auto] Hello guys. Welcome to this class. So in this class we are going to be learning how to get the address of a place using the location coordinates. So the example of what we want to achieve is if we move our map to a new place to a new point to automatically update our address if we move to new points of the address. So what is going on here is that we are using the Google decoding API to transform our location coordinates and into return a format and address for us. Right. So this actually comes in handy because once you are into the app it's always get your complication. So you don't need to say this again provided that you're starting your team from the place you are. So this is really very very useful. So it is probably going to be a long class. So guys let's just get right into it. So I think this is the first thing we need to do will be to enable our Google decoding API. We need to go to our Google Developer control to do that right. Some already in my own developer account. So what I need to do now is to select my project which is clone so when downloads of our good new library then I'll look for Google recording API. It's on their maps. So it shows the all and this what we are looking for equity API as you can see it says convert between addresses and geographic coordinates. So we are going to enable a OK API enabled so click on enable you to enable it. Right. So I need to also making loans. All right. This particular API may require you to provide your billing information. Right. So our advice is that you go ahead and activate your 300 dollars free Google created right to be able to use this particular API because you may be getting some errors. All right. Are you permanent knowing that this is the course of a. So I would just go ahead and activate my imaginary access to provide some billing information which is OK. So just go ahead and continue with that. So now you always you know be able to use the API smoothly without any issues. So I'm going to go ahead and fill in my own information. So I suggest you do that for us as well so I'm going to be filling my information now. Guys so my billing is well set up. I can now confidently use the API now that we've enabled the API. We need to head back into our app. OK. So now the first thing we need to do will be to create a new file and we're going to call it a math function helper. So it is actually going to puts in all functions that has to do with maps against you know our location coordinate and the rest of other stuffs. So again it's in your file and we're going to call on a map function function helper. So now we're done with this. So the way to use that recording API is we're passing our location coordinates to Pasquale you around. OK. So easy to make a web request and we will expect adjacent string in return. And it uses string we have the format and address. So guys I'm going to show us example of what I mean. So this is a query to particular coordinates to this coordinate. OK. So this is the URL that we query and we are passing it disquieting in these coordinates Zack ordinates and also we are passing in our EBIT. So in the end it would give us format and address. This is what we are actually looking for. OK. So there is less going into our corner and do this. So the first thing we need to do is to define a new function now return the string because we need to view the new Arrow first. Okay so we're gonna call this get geo called you around okay. And this function we need to pass it. Our latitude and longitude came so I'm going to say string you know equal to the Google API is dot com slash okay. So let's go ahead and verify that this is correct maps. Google API dot com slash maps slash API you could do so right. So this is very correct. So we're going to add our latitude value for latitude. We're going to add a comma we're going to add in value for longitude and we're going to add our key so we need to define our map key as a global variable because we're going to be using it later on in the app. OK. So when we define it as a global variable that means that we need to bring it in when we are initializing this particular class. Right. So we're going to parse this in the constructor. So as you guys know the easy constructor we need to when we initialize in this particular class we need to provide our map key. Right. So we're going to say string in the key right. Is a map key code to map key right. So we're not done here we need to return this case we're going to see a return you know. Good. So that is a nice thing to do now be to make a web request to dispatch Quinn are you around. OK so this web we need to be seeing Cronin. So we need to use it head to GP client. You need the two ways of making a web request. Number one is truly using a normal web request. And the second one is using a headset to be client. So it has to be client comes in handy when you want to make synchronized your request and you're expecting a Jason string as your response. This is actually a shorthand and it's much easier. But when you want to make a request on your or you mentioned then you probably need to use the web request and when you want to monitor your response and actually the data you send in. You want to monitor every single thing. Then you way request this tape is the way to go. All right. Well we'll just make use of the heads as we claim these quite very short hand and straight to the point. We're going to say probably soon get Jewel and Jason sync. All right. So now we need to pass. Are you on now. I see parameter to this particular matter. Right. As a string around. OK. So now what we need to do we're going to see var handler quote to new CTP. So we need to bring any reference to our Haiti simply client. So if you actually do a visual studio how to find is by clicking on your project title Duran click on it. You click on Add you will see reference. OK well if you're using a vicious do you for Mark go to project click on edit reference. All right so we're gonna search for sustained high CTP send on NATO Haiti 2P and we're going to take it. We're going to take systemd on that as well. So we need to bring in these two references to be able to make use of our heads to be client. OK so what is shifting this. Go ahead and click. OK so what are projects is saved. We can go ahead and say hey TTP planned and LA so let's bring in the reference. OK well we're good so the next year we're going to say hey TTP client unicorn is client code to new clients and we're going to pass it to a handler came when it's a String result of code to find don't get string sync so it is an synchronous moto and so we need to change these to change the format of our method. It has to be an synchronous task. OK so we're going to need two changes to sync task so I'm going to bring a reference of task system and trade into a task OK of type of string OK so at this point you're going to add weight to causes and we take will function we're going to pass our you around. So this works well the last thing you're going to do is you see a return result. OK. So it is a return result for us. Right. So the last thing we need to do would be to create a new method that will actually decode the result that will get from these particular requests. OK. Like I mentioned earlier this is the kind of restaurant that we're expecting when we make now every request. OK. The format it addresses what we are actually looking for. So it is the kind of data that we expected. So we need to realize this data. OK. So that's what we're going to be doing here. So this map we're going to call it find coordinate address. So we're going to say public public async task to say probably I think task of type of string we're going to call it find coordinate address. OK. So we need to a passive position. All right. So our position should be in the form of latitude and longitude values so we can use our latitude and longitude object of the map. So for us to fully set up these spots are going to matter and we need to pass it's a position the position need to be in a form of latitude and longitude. So we're going to use a lot of launch object so we're going to say that lunge we're going to bring in the reference map model inequality position. This would actually mean our current position. So whenever we swipe on the map our new position is where we are going to be sending to these particular meantime. All right. So now that we've done that. So whenever our code is function I'm passing our position we need to get you around. That's what we now call indispensable a method. So we're gonna say so as this string Euro code to win a safe string Euro code to get your code a Euro position or latitude position longitude K so let's define string. So in so we're gonna use this to collect the value of our J zone and we're can use this to collect the value of our place address. Okay. So the next two you need to do is to Napoli make our request OK. So it's make our points we're going to say Gee. So we're going to wait drew Jason. I think we're going to pass it. Are you around so like I said earlier making use of the hedges clients is very handy and very shorthand. So as you can see this will actually return naturally make the requests and returned to this Jason stream. So the next thing we're going to do is to realize these particular Jason. Right. So to be able to relate these Jason will have to make a new class more don't need to worry about that because of a very demanding class. So that is we need to go ahead and download the class and added to our projects. So I'm going to add decoding bias to a project and we'll go over it once and for all. This found resources and these are equity impasses I'm going to go ahead and add it so guys this open and bias and see what we have inside this class actually helps us to serialize the data that chunk of data decentralizing node by node and it helps us to find our formatted address. So guys we are going to go back into a malfunction helper and make use of these Euclidean parser. So we need to first of all check if Jason's string is actually a real string. So we're going to say if string son so little guys we can actually need to be checking for internet connection. We come back to this I'm going to just one comment here so that we know that we need to do it okay so let's continue. So we gone quiet on this serialization. Jason we need to install Jason nugget package. We've not started up to this point. So we need to go to our package manager and get so let's go ahead and download the new to soft. Jason So this is what we looking for. So we go into this package is actually hard for us to walk. Jason found so the package just added what you need help us to be able to walk while we are adjacent strings. OK so to do that we're going to see var g code data called Data equal to Jason combat. So is bringing these reference you so convert OK so let's continue. Don't do Syria realize does realize object or geo code Jokowi in passing so let's bring in the reference to this spectacle of file OK so now that we have that we can pass it our Jason so despite our line of code we decentralize Jason Street and make it easier for us to assess the data inside of it. So now we just gonna go ahead and get our place results. So before that we're going to ensure that I statues is not zero so these checks are very important so that you know is going on. So this is to ensure that our Jason contains some results. OK. So we're going to go ahead and say please address the quote to you could data don't results zero not formatted address so guys this is actually what we are looking at the results as you can see. The first one that we got back the first results. That is the results with the index of zero these days. So for this particular location coordinates if I wanted to address that we actually would have picked if we actually doing this from an app is actually cool. All right. So if you go down you find out that there are some other formatting addresses for the most reliable is always the first one. So always go ahead and choose the first one. OK so let's go back on our code. So when we selected our place in dress we need to return it. OK we're going to go in and see a return let's address mom. So bam. So we are done with this. Now we need to go to our main activity. So we need to add a new event handler to our map. So whenever our map receives a movement and this I don't want it to drink it up I took in the meantime I want to go and I may turn. So we're going to go to our map ready so my I'm I'm going to add a new event handler to our map. OK. So we're going to say main map dots. I do come here I do rather signs the name says this event is always drink I win if I become a right I do. So when you move your map and it moves to a new point and the camera becomes I do it to a fire this event. So in this event and we'll always call these mental ill defined coordinate address. OK so let's go ahead and set it on a equal to OK OK. So now those set of dysfunction means you create an instance of our map function helper. All right. So we need to make it a global variable so that we can always assess it from anywhere within our application so we can go ahead and say we want to keep things a little bit organized so I'm going to call these helpers so we're going to see a mob function named for inequalities mapping helper OK. So I want initializing when map is ready. OK. So it is we I actually want to initialize this so before we go ahead and initialize our map function helper need to lay hands on our map key. OK. So we're going to say string map key. You guys remember we had it in our string the Asimo so this is our monkey monkey. We can use it for any of the EPA that has to do with maps. OK so we need to actually grab this. OK. So to do that we're going to say resources the guest stream we're going to pass it on a string resource those stream map key. OK. So this will actually give us our map key. So we're going to see map helpers quotes a new map function helper. We're going to pass it our map key. OK so this would actually do the magic for us. So now successfully instantiated our map function apart when our map has completely loaded. So we're going to go ahead and say pick up location test because Israel wants to displace the new address that we just got from our API. So we're going to say map but don't find coordinate address. OK. So that's a finalized with this. We need to pass in our position. So to again opposition we need to know exactly we had a map stopped. We need to know exactly where our map is pointing out. OK. So to do that we need a new instance of latitude and longitude and these would be equal latitude and longitude where this needs to be a global variable so that we can always assess it. OK. So let's go on top of our class records Jim details we're gonna say not lunch when all these people location launch. OK. So now let's go back to our com era. I do. Event Handler OK so now we're going to say up not launch will be equal to equal to men. Dot com in our position. So we're gonna get our come in opposition. OK come in position on target. So it is a return a lot launch instance for us. OK so this will actually be position will Bositis function. So many positives that merge. So as you guys remember this is a table function right. This is in our synchronous function. OK. So we need to make this a sync as well racing. We need to wait to displace so that's all we need to do. So guys this is just how to do that. So we need to narrow on our application and ensure that everything works perfectly well. OK so let's run a good. So Sims is working. So he's working just the way we expected it's going to see our location is being on data you can see on location is being updated. So guys this is just how straightforward it is to get our address using our location coordinates. So thank you very much for watching. I really hope you enjoyed the class. So see you in this class.