How to get latitude, longitude and address in android
-
Possible Duplicate: http://stackoverflow.com/questions/4345535/how-to-retrieve-the-gps-location-via-sms I am making an android application that is going to act like this: When a user types a text message containing for example "findmyphone" or anything like that (it will not respond to other normal text messages) to the phone that is running the application, the application will automatically respond to that number with latitude, longitude and the address of the phone that is running the application. I also need a button for testing it. And once the user presses the "Test" button, the latitude, longitude and address will appear in 2 textboxes, latitude and longitude in one, and the address in the other one. Thanks SO much in advance! This is what I have so far: import java.io.IOException; import java.util.List; import java.util.Locale; import android.app.Activity; import android.content.Context; import android.location.Address; import android.location.Geocoder; import android.location.Location; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; public class FindAndroidActivity extends Activity implements OnClickListener { /** Called when the activity is first created. */ Button Nextbutton1, Nextbutton2, TestLocationService; TextView Cordinates, Adress, FindAndroid; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Nextbutton1 = (Button)findViewById(R.id.Nextbutton1); Nextbutton1.setOnClickListener(this); } public void onClick(View src) { switch (src.getId()) { case R.id.Nextbutton1: setContentView(R.layout.setup); Nextbutton2 = (Button)findViewById(R.id.Nextbutton2); Nextbutton2.setOnClickListener(this); TestLocationService = (Button)findViewById(R.id.TestLocationService); TestLocationService.setOnClickListener(this); break; case R.id.Nextbutton2: setContentView(R.layout.main); break; case R.id.TestLocationService: break; } } public Address getAddressForLocation(Context context, Location location) throws IOException { if (location == null) { return null; } double latitude = location.getLatitude(); double longitude = location.getLongitude(); int maxResults = 1; Geocoder gc = new Geocoder(context, Locale.getDefault()); List<Address> addresses = gc.getFromLocation(latitude, longitude, maxResults); if (addresses.size() == 1) { return addresses.get(0); } else { return null; } } }
-
Answer:
I will not give detailed instructions on anything because you can do a google search or search StackOverflow for most information that you need. To get a location, you would use http://developer.android.com/reference/android/location/LocationManager.html and invoke requestLocationUpdates. There are plenty of tutorials that explain how to do this. To receive an sms, you would need a http://developer.android.com/reference/android/content/BroadcastReceiver.html declared in your Manifest like the following: <receiver android:name=".SmsReceiver"> <intent-filter> <action android:name="android.provider.Telephony.SMS_RECEIVED"/> </intent-filter> </receiver> Within this receivery you would use the http://developer.android.com/reference/android/telephony/SmsMessage.html class to get the necessary info from the sms. Then to send an sms back, you would use http://developer.android.com/reference/android/telephony/SmsManager.html and invoke sendTextMessage. BUT: You really need to do the work on your own. It's also good to note that there are a TON of phone locator applications on the Market already, so this might not be a worthwile app for you to make. And again, you can search stackoverflow or http://google.com to find out how to do each thing that you're needing. And if you haven't done any actual Android programming (since you said you used app inventor), then you need to look at the http://developer.android.com/guide/basics/what-is-android.html
MySoftware at Stack Overflow Visit the source
Related Q & A:
- How Can I add Latitude, Longitude dynamically in Javascript?Best solution by Stack Overflow
- How to get nearest address of a random latitude and longitude?Best solution by Stack Overflow
- How to get accurate latitude and longitude in Android?Best solution by Stack Overflow
- How to get to the alarm clock on Android?Best solution by eHow old
- How to get a second email address?Best solution by eHow old
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.