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 

 



 

114 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. This comment has been removed by the author.

    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. Thank You for Sharing this wonderful and much required information in this post.
    Agile DevOps Services in UK

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

    ReplyDelete
  48. 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
  49. It looks quite interesting! Keep posting the great content. We are the best .net development company in Ahmedabad, India

    ReplyDelete
  50. 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
  51. Great! i gained knowledge while reading your blog .Keep Sharing

    Data Science Training in Pune

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

    ReplyDelete
  53. 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


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

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

    ReplyDelete
  56. 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
  57. 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
  58. 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
  59. 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
  60. 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
  61. 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
  62. very nice blog,
    https://iqratechnology.com

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

    ReplyDelete
  64. 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
  65. 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
  66. 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
  67. 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
  68. 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
  69. This capability has wide-ranging applications, from improving location-based services to enhancing geographic data analysis. Thank you.
    Data Analytics Courses In Chennai

    ReplyDelete
  70. 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
  71. Thanks for sharing insightful and informative tutorial on How to get a longitude & latitude from a given Address.
    data analyst courses in limerick

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

    ReplyDelete
  73. 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
  74. 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
  75. Longitude and latitude are geographic coordinates used to pinpoint locations on Earth. Latitude measures distance north or south of the equator, while longitude measures east or west of the Prime Meridian.
    Data science courses in Gurgaon

    ReplyDelete
  76. This blog is a treasure! Your insights are always relevant, and I appreciate the way you encourage thoughtful discussion among your readers. Keep up the great work

    Data science courses in Gujarat

    ReplyDelete
  77. This article is incredibly informative and well-structured. The content is both thorough and easy to follow, which made it a pleasure to read. I’m sure many others will benefit from it just as I did. Thanks for writing this.
    Data Analytics Courses in Delhi

    ReplyDelete
  78. Nice information on how to get longitude latitude from the address by simple coding method and neatly explained.
    Online Data Science Course

    ReplyDelete
  79. Such a refreshing take on how to get longitude and latitude from address topic. Well done and good content.
    Online Data Science Course

    ReplyDelete
  80. This was an enlightening read! Your thoughtful reflections have encouraged me to think critically about my own experiences and beliefs.

    Data science courses in Mumbai

    ReplyDelete
  81. Your advice on how to get latitude and longitude really resonates with me. I can’t wait to implement some of these tips.
    Data Science Courses in China


    ReplyDelete
  82. I didn't know that you can derive longitude and latitude from the given address.
    great article.
    Data science courses in chennai

    ReplyDelete
  83. This blog post provides a clear and concise guide on how to retrieve longitude and latitude from an address using Android. The step-by-step instructions, along with the code examples, make it easy for developers to follow and implement this functionality in their own projects.
    Data science courses in Bangladesh

    ReplyDelete
  84. Thank you for your post. This is excellent information. It is amazing and wonderful to visit your blog.
    Data Science Course in Kolkata

    ReplyDelete
  85. Your tutorial on getting longitude and latitude in Android is so practical and easy to follow! I love how you’ve included clear instructions and examples to make the process smooth. This is a great resource for Android developers.
    Data science course in Gurgaon

    ReplyDelete