Wednesday, November 7, 2012

How to get a longitude & latitude from a given Address

 How to get a longitude & latitude from a given Address

Step 1
   Copy pate following code in main.xml
 
 <?xml version="1.0" encoding="UTF-8"?>

       <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
              android:layout_height="wrap_content" android:layout_alignParentBottom="true"
              android:orientation="vertical">
              <EditText android:id="@+id/location" android:layout_width="fill_parent"
                     android:layout_height="wrap_content" android:text="Address here..." />
              <Button android:id="@+id/geocodeBtn" android:layout_width="wrap_content"
                     android:layout_height="wrap_content" android:text="Search" />
              <TextView android:id="@+id/position" android:layout_width="fill_parent"
                     android:layout_height="wrap_content"  />
       </LinearLayout>

Step 2
  Copy paste following Code in your Main Activity Class...
  In here your package name and your Main Activity Class name is different from my code ......

package com.adrianfindaddress;

import java.util.List;

import com.google.android.maps.GeoPoint;

import android.location.Address; 
import android.location.Geocoder; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.TextView; 
 
import com.google.android.maps.GeoPoint; 
import com.google.android.maps.MapActivity; 
import com.google.android.maps.MapView;

public class AdrianLocationFinderActivity extends MapActivity {
    /** Called when the activity is first created. */
        Geocoder geocoder = null; 
        
           @Override 
           protected void onCreate(Bundle savedInstanceState) { 
               super.onCreate(savedInstanceState); 
               setContentView(R.layout.main); 
       
            
               Button geoBtn = (Button) findViewById(R.id.geocodeBtn); 
        
               geocoder = new Geocoder(this); 
        
               geoBtn.setOnClickListener(new OnClickListener() { 
        
                   @Override 
                   public void onClick(View v) { 
                       try { 
                           EditText locale = (EditText) findViewById(R.id.location); 
                           String locationName = locale.getText().toString(); 
        
                           List<Address> addressList = geocoder.getFromLocationName( 
                                   locationName, 5); 
                           if (addressList != null && addressList.size() > 0) { 
                               int lat = (int) (addressList.get(0).getLatitude() * 1e6); 
                               int lng = (int) (addressList.get(0).getLongitude() * 1e6); 
        
                               TextView displayLocation= (TextView) findViewById(R.id.position); 
                               displayLocation.setText("lat: " 
                                       + addressList.get(0).getLatitude() + " lng: " 
                                       + addressList.get(0).getLongitude()); 
        
                              
                           
                           } 
                       } catch (Exception e) { 
                           e.printStackTrace(); 
                       } 
                   } 
               }); 
           } 
        
           @Override 
           public boolean isLocationDisplayed() { 
               return false; 
           } 
        
           @Override 
           public boolean isRouteDisplayed() { 
               return false; 
           } 
       } 

 
Step 3
   AndroidManifest.xml  ... Add user permission

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.adrianfindaddress"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="4" />
   
     <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
 

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
       
           <uses-library android:name="com.google.android.maps" />
       
       
        <activity
            android:name=".AdrianLocationFinderActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Step 4

Now Run the App....


Good Luck!

 Tutorial List 

 



 

105 comments:

  1. this code is not working...
    not even offline and online...

    ReplyDelete
  2. did you add user permission... in manifest






    ReplyDelete
  3. you can get LatLng and show on map

    ReplyDelete
  4. How to get current address like "karolbagh, Delhi"

    ReplyDelete
  5. I agree with the most of the contents in this article and it’s great without any doubt. I think you made some good points in Features also. Really an amazing post! I would like to suggest your blog in my friend’s circle. Here I find everything in details. I hope I will see this type of post again in your blog.
    Engineering Colleges in Chennai, Mechanical Engineering Colleges in Chennai

    ReplyDelete
  6. It's like you read my mind! You seem to know a lot about this, like you wrote the book in it or something. I think that you can do with some pics to drive the message home a little bit, but instead of that, this is fantastic blog. A great read. I will definitely be back.
    Selenium Training in Chennai

    ReplyDelete
  7. I am a regular reader of your blog. Very nice and inspiring post. Thanks for sharing. Online Android App Development Course In Noida

    ReplyDelete
  8. Thank you for taking the time and sharing this information with us. It was indeed very helpful and insightful while being straight forward and to the point.
    Java training in Bangalore | Java training in Kalyan nagar

    Java training in Bangalore | Java training in Kalyan nagar

    Java training in Bangalore | Java training in Jaya nagar

    ReplyDelete
  9. I read this post two times, I like it so much, please try to keep posting & Let me introduce other material that may be good for our community.
    excel advanced excel training in bangalore
    Devops Training in Chennai

    ReplyDelete
  10. It would have been the happiest moment for you,I mean if we have been waiting for something to happen and when it happens we forgot all hardwork and wait for getting that happened.
    angularjs Training in bangalore

    angularjs Training in bangalore

    angularjs interview questions and answers

    angularjs Training in marathahalli

    angularjs interview questions and answers

    angularjs-Training in pune

    ReplyDelete
  11. Thank you for giving the information and it is use full for me. training with placement company in Hyderabad

    ReplyDelete
  12. Thanks for sharing the good information and post more information. I need some facilitate to my website. please check once http://talentflames.com/
    training and placement company in Hyderabad

    ReplyDelete

  13. It’s amazing in support of me to truly have a web site that is valuable meant for my knowledge.

    Still Hunting Method
    Hunting psych tips Survival Tips Travel Touring Tips

    ReplyDelete
  14. This comment has been removed by the author.

    ReplyDelete
  15. This comment has been removed by the author.

    ReplyDelete
  16. My gratitude for the wonderful words. We want you to continue this for us.
    Graphic Designing in Coimbatore Visit https://weassistplus.in/
    A Super Specialized place for Web Designing, Logo Designing, Brochure, Stationary items, google ads, Social Media Analyst, SEO maintenances for your company.

    ReplyDelete
  17. This comment has been removed by the author.

    ReplyDelete
  18. This comment has been removed by the author.

    ReplyDelete
  19. This comment has been removed by the author.

    ReplyDelete
  20. Really very happy to say, your post is very interesting to read. I never stop myself to say something about it. You’re doing a great job. Keep it up…

    Start your journey with RPA Training in Bangalore and get hands-on Experience with 100% Placement assistance from experts Trainers @Softgen Infotech Located in BTM Layout Bangalore. Expert Trainers with 8+ Years of experience, Free Demo Classes Conducted.

    ReplyDelete
  21. Hello, I like your post and really wanna admire your work. I am totally impressed with this blog post. Thank you so much for sharing this wonderful information. Poker Game Development Company

    ReplyDelete
  22. I absolutely love that it looks so beautiful on you This is a great post it was very informative. I look forward in reading more of your work. Also I made sure to bookmark your website. I enjoyed every moment of reading it. More info please visit :-
    Mobile Apps Development Company in Gurgaon
    IOS Apps Development Company in Gurgaon
    Android Apps Development Company in Gurgaon
    Software Company in Gurgaon
    Web Development Company Gurgaon
    Web Design and Development company in Gurgaon
    Web Designing Company in Gurgaon

    ReplyDelete

  23. I really appreciate this post and I like this very much. I am waiting for new post here and Please keep it up in future.. Website Development Sydney. Visit us https://www.designpluz.com.au

    ReplyDelete
  24. I think you did an awesome job explaining it. Sure beats having to research it on my own. Thanks
    Rajasthan University BCOM 1st, 2nd & Final Year Time Table 2020

    ReplyDelete
  25. Thanks for sharing this blog. This very important and informative blog...
    Informatica Bangalore

    ReplyDelete
  26. Well Said, you have furnished the right information that will be useful to anyone at all time. Thanks for sharing your Ideas.


    Selenium Training in Electronic City

    ReplyDelete
  27. They're produced by the very best degree developers who will be distinguished for your polo dress creating. You'll find polo Ron Lauren inside exclusive array which include particular classes for men, women.

    data analytics courses

    data science interview questions

    business analytics courses

    data science course in mumbai

    ReplyDelete
  28. Nice post I have been searching for a useful post like this on salesforce course details, it is highly helpful for me and I have a great experience with this, Salesforce Certification Australia  

    ReplyDelete
  29. Hey, i liked reading your article. You may go through few of my creative works here
    Jobs.promaxbda
    Publicatom

    ReplyDelete
  30. Thanks for sharing great information. I like your blog and highly recommendData Science Training in Hyderabad

    ReplyDelete
  31. Its such as you learn my mind! You appeаr tо grasp ѕo much approximately this, such as you wrote the book in it or something.
    I think that you could ɗo wіth some percent to pressure the mesѕage home a little bit,
    but instead of that, this iѕ excellent blog. An excellent
    read. I ԝilⅼ defіnitely be back.
    sap training in chennai

    sap training in velachery

    azure training in chennai

    azure training in velachery

    cyber security course in chennai

    cyber security course in velachery

    ethical hacking course in chennai

    ethical hacking course in velachery

    ReplyDelete
  32. If you are searching out unfastened lottery recreation hints, you can have an easy time locating them at the decent website kbc lottery winner 2020 35 lakh . They offer a diffusion of guidelines that you can have a look at and enjoy the lottery games extra.

    ReplyDelete
  33. Actually I read it yesterday but I had some thoughts about it and today I wanted to read it again because it is very well written.
    Data Analyst Course

    ReplyDelete
  34. I curious more interest in some of them hope you will give more information on this topics in your next articles.
    data science training

    ReplyDelete
  35. https://naxtre.blogspot.com/2020/10/best-magento-development-services.html?showComment=1605695853668#c2030061707718398261

    ReplyDelete
  36. Data Science course was never so easy and adaptable to everyone but here at Excelr We teach you numerous ways of doing Data Science Courses, which are way easy and interesting. Our experienced and expert faculty will help you reach your goal. 100% result oriented strategies are being performed; we offer Data Science Course in pune

    Data Science Courses

    ReplyDelete
  37. Feeling good to read such a informative blog, mostly i eagerly search for this kind of blog. I really found your blog informative and unique, waiting for your new blog to read.
    Digital marketing Service in Delhi
    SMM Services
    PPC Services in Delhi
    Website Design & Development Packages
    SEO Services Packages
    Local SEO services
    E-mail marketing services
    YouTube plans

    ReplyDelete
  38. ery well explained. I would like to thank you for the efforts you had made for writing this awesome article. This article inspired me to read more. keep it up.
    Logistic Regression explained.salesforce training in chennai

    software testing training in chennai

    robotic process automation rpa training in chennai

    blockchain training in chennai

    devops training in chennai

    ReplyDelete
  39. Excellent blog thanks for sharing the valuable information..it slit transplantation technique

    ReplyDelete
  40. This paragraph gives clear idea for the new viewers of blogging, Thanks you.

    Java Training in Chennai

    Java Course in Chennai

    ReplyDelete
  41. This comment has been removed by the author.

    ReplyDelete
  42. Having a mobile app built for your business or side hustle is great—unless it's not. A poorly executed mobile app can leave a bad taste in the mouths of your customers, you, and even your employees. Whether you've outgrown your current app or you'd like to make a big splash with your next big project, it's time to start shopping around for a good mobile app development company.

    ReplyDelete
  43. Nice Article, Thank you for sharing a wonderful blog post, I loved your blog post.

    You can also check - Telemedicine App Development Company

    ReplyDelete
  44. I visited various websites but the audio feature for audio songs current at this site is really wonderful.|
    data scientist training and placement in hyderabad

    ReplyDelete
  45. Thank you for sharing this article really loved your blog keep posting this kind of stuff
    Data Scientist Course

    ReplyDelete
  46. This is great:https://www.cheapassignmentwriters.com/

    ReplyDelete
  47. Good blog. Keep sharing. I love them Are you also searching for ajman assignment help? we are the best solution for you. We are best known for delivering writing services to students without having to break the bank

    ReplyDelete
  48. Thank You for Sharing this wonderful and much required information in this post.
    Agile DevOps Services in UK

    ReplyDelete
  49. This comment has been removed by the author.

    ReplyDelete
  50. Great information! Thanks for sharing. (How to get a longitude & latitude from a given Address would be more easyfor us..)

    We provide web & mobile app development services.

    asp .net core development company, asp .net core development services, asp .net development services

    ReplyDelete
  51. It looks quite interesting! Keep posting the great content. We are the best .net development company in Ahmedabad, India

    ReplyDelete
  52. The web is a great place to go if you are looking for apps to help you with your business. While you can find apps for almost everything on the web these days, finding those that are designed specifically for web and mobile app development can be difficult. Luckily, the web and mobile app development blog exists to help you sort through the clutter and find the right apps for your business.

    ReplyDelete
  53. Great! i gained knowledge while reading your blog .Keep Sharing

    Data Science Training in Pune

    ReplyDelete
  54. This blog is so nice to me. I will keep on coming here again and again. Visit my link as well.. mobiele airco

    ReplyDelete
  55. Great blog post. I used to be checking continuously this blog and I am impressed! Extremely helpful information specially the closing phase :) I deal with such info a lot.

    ReplyDelete


  56. Thanks for this informative blog, keep sharing your thoughts like this.
    Scrum planning
    Scrum Methodologies

    ReplyDelete
  57. Very awesome blog. Great stuff. Informative content. Very useful to many people. Keep up this good work.
    Data Scientist Training in Hyderabad

    ReplyDelete
  58. I think this is a standout amongst the most critical data for me. What"s more, i"m happy perusing your article. Be that as it may, ought to comment on some broad things data science training in surat

    ReplyDelete
  59. I’ve been browsing online more than 3 hours today, yet I never found any interesting article like yours. It’s pretty worth enough for me. In my opinion, if all webmasters and bloggers made good content as you did, the internet will be much more useful than ever before.

    B.B.A Exam Schedule | BCA 1st 2nd 3rd Final Year

    ReplyDelete
  60. Artoon Solutions is a leading IT company that provides Game Development services like Poker Game Development, Rummy Game Development, Solitaire Game Development, Call Break Game Development, and much more.

    ReplyDelete
  61. Positively, generally speaking, particularly interesting post. I was looking for such an information and totally valued the experience of checking this one out. Keep on posting. A commitment of appreciation is all together for sharing.data scientist course in bhubaneswar

    ReplyDelete
  62. thanks For sharing this top notch article.i exploit this newsletter to function my venture in college.it's far beneficial For me amazing paintings. Sony Vegas Pro 20

    ReplyDelete
  63. Malwarebytes Anti Malware Premium Serial Key that is my first duration i go to right here and i discovered consequently many enthralling stuff for your blog specifically it is aeration, thank you.

    ReplyDelete
  64. Brother Day Images Happy brothers day! To have a brother like you is a blessing! that is truely intellectual content material and written thinking about ease for a regulate. it's best to peer that some human beings but put taking region as soon as a way to write a man or woman nation.!

    ReplyDelete
  65. Nice blog, the web and mobile app development blog exists to help you sort through the clutter and find the right apps for your business.
    we provide IT service.
    iqratechnology4@gmail.com

    ReplyDelete
  66. very nice blog,
    https://iqratechnology.com

    ReplyDelete
  67. Thanks for posting the best information and the blog is very imp,
    https://iqratechnology.com/

    ReplyDelete
  68. Coolearth is one of the leading vrf hvac services, manufacturers and Suppliers. Visit our website for best chiller manufacturers, ahu manufacturers in india, and healthcare solution providers in india.
    Healthcare Solution Providers in India

    ReplyDelete
  69. Pulprolls is one of the leading 5730 5725 5715 Thermal Credit Card Swipe Machine POS Paper Rolls Manufacturer in India. Visit our website for more information.
    5730 5725 5715 Thermal Credit Card Swipe Machine POS Paper Rolls Manufacturer

    ReplyDelete
  70. Vietnam Eximp is a leading Import Export Trade Data provider for 100+ countries like usa, Russia, united kingdom, Singapore and more. For more information in details visit our website.
    Vietnam Import Data

    ReplyDelete
  71. Hello Blogger,
    Thank you for this clear and concise tutorial on how to get a longitude and latitude from a given address in Android. I especially appreciate the clear instructions and the inclusion of code snippets. Your tutorial is well-written and easy to follow, and I am confident that it will be helpful to many Android developers.
    Data Analytics Courses In Dubai

    ReplyDelete
  72. I appreciate you providing this simple and clear instruction on how to use Android to find the longitude and latitude of a given address. I particularly value the concise explanations and the use of code samples. Your guide is clear and well-written, and I have no doubt that it will be useful to lots of Android developers.
    Data Analytics Courses in Agra

    ReplyDelete
  73. This capability has wide-ranging applications, from improving location-based services to enhancing geographic data analysis. Thank you.
    Data Analytics Courses In Chennai

    ReplyDelete
  74. The step-by-step guide on how to obtain longitude and latitude from an address is incredibly useful, and the detailed explanations make it accessible for all.
    Digital marketing courses in illinois

    ReplyDelete
  75. Thanks for sharing insightful and informative tutorial on How to get a longitude & latitude from a given Address.
    data analyst courses in limerick

    ReplyDelete
  76. thanks for sharing such informative blog post, really well explained
    Digital marketing business

    ReplyDelete
  77. This very impressive and interesting blog is found to be well written in a simple manner that everyone will understand and gain enough knowledge from your blog being more informative .
    Digital marketing courses in city of Westminster

    ReplyDelete
  78. Excellent guide on obtaining longitude and latitude from an address! The step-by-step instructions and the use of coding services make it accessible for everyone. I appreciated the practical examples you provided. Thank you for this article.
    Data analytics framework

    ReplyDelete