I'm using the following code to create a map and attach a marker to it. I'm also adding a marker listener where I need to get the longitude and latitude of the marker position after dragging.
What it does is returnning my current location not the location of the marker after drag.
Any help with this part?!
package com.example.mysample;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMarkerDragListener;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.Projection;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptor;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.maps.GeoPoint;
import android.location.Location;
import android.location.LocationListener;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.view.MotionEvent;
import android.widget.Toast;
import android.graphics.*;
public class MainActivity extends FragmentActivity implements LocationListener {
GoogleMap map;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GooglePlayServicesUtil
.isGooglePlayServicesAvailable(getApplicationContext());
map = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();
map.setMyLocationEnabled(true);
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
map.addMarker(new MarkerOptions()
.position(new LatLng(0, 0))
.title("Marker")
.draggable(true)
.snippet("Hello")
.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_YELLOW)));
map.setOnMarkerDragListener(new OnMarkerDragListener() {
#Override
public void onMarkerDragStart(Marker marker) {
// TODO Auto-generated method stub
// Here your code
Toast.makeText(MainActivity.this, "Dragging Start",
Toast.LENGTH_SHORT).show();
}
#Override
public void onMarkerDragEnd(Marker marker) {
// TODO Auto-generated method stub
Toast.makeText(
MainActivity.this,
"Lat " + map.getMyLocation().getLatitude() + " "
+ "Long " + map.getMyLocation().getLongitude(),
Toast.LENGTH_LONG).show();
System.out.println("yalla b2a "
+ map.getMyLocation().getLatitude());
}
#Override
public void onMarkerDrag(Marker marker) {
// TODO Auto-generated method stub
// Toast.makeText(MainActivity.this, "Dragging",
// Toast.LENGTH_SHORT).show();
System.out.println("Draagging");
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public boolean onMarkerClick(final Marker marker) {
if (marker.equals(map)) {
// handle click here
// map.getMyLocation();
System.out.println("Clicked");
double lat = map.getMyLocation().getLatitude();
System.out.println("Lat" + lat);
Toast.makeText(MainActivity.this,
"Current location " + map.getMyLocation().getLatitude(),
Toast.LENGTH_SHORT).show();
}
return true;
}
#Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
}
#Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
#Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
#Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
Take a look at this function in your code.
#Override
public void onMarkerDragEnd(Marker marker) {
// TODO Auto-generated method stub
Toast.makeText(
MainActivity.this,
"Lat " + map.getMyLocation().getLatitude() + " "
+ "Long " + map.getMyLocation().getLongitude(),
Toast.LENGTH_LONG).show();
System.out.println("yalla b2a "
+ map.getMyLocation().getLatitude());
}
Here you are trying to get your current location on map which is wrong you should get location of marker that you dragged. You already have "marker" object here. Use that to get location of this draged marker's location.
LatLng position = marker.getPosition(); //
Toast.makeText(
MainActivity.this,
"Lat " + position.latitude + " "
+ "Long " + position.longitude,
Toast.LENGTH_LONG).show();
It s quite simple i think if you want the long and lat coordinates with a long press ...
First, you have to do GoogleMap.setOnMapLongClickListener(this);
and add to the signature of the containing class: implements OnMapLongClickListener
And here is the code:
#Override
public void onMapLongClick(LatLng point) {
Toast.makeText(MainActivity.this, point.latitude+" "+point.longitude, Toast.LENGTH_SHORT).show();
}
Related
I want to make multiple polyline in map. i have one polyline in maps, then i want to make new polyline again. but the line is always connect with previous polyline. what should i do, this is my code:
package com.evy;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONArray;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMapLongClickListener;
import com.google.android.gms.maps.GoogleMap.OnMarkerDragListener;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.GoogleMap.OnMapClickListener;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.maps.model.Polyline;
import com.google.android.gms.maps.model.PolylineOptions;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.Toast;
public class Tambah extends FragmentActivity implements LocationListener{
GoogleMap map;
LocationManager lm;
boolean isNewPoly=false;
PolylineOptions polyline;
ArrayList<LatLng> poly = new ArrayList<LatLng>();
ArrayList<LatLng> points = new ArrayList<LatLng>();
PolylineOptions polylineOptions;
#Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.tambah);
//points=new ArrayList<LatLng>();
lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.maptambah);
map=mapFragment.getMap();
final LocationListener ll=new LocationListener(){
#Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
map.addMarker(new MarkerOptions().position(new LatLng(location.getLatitude(),location.getLongitude())).title("posisi anda").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
map.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(),location.getLongitude()), 15.0f));
}
#Override
public void onProviderDisabled(String arg0) {
// TODO Auto-generated method stub
}
#Override
public void onProviderEnabled(String arg0) {
// TODO Auto-generated method stub
}
#Override
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
// TODO Auto-generated method stub
}
};
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll);
Button stop = (Button) findViewById(R.id.stop);
Button start = (Button) findViewById(R.id.start);
map.setOnMapClickListener(new OnMapClickListener(){
#Override
public void onMapClick(LatLng point) {
// TODO Auto-generated method stub
if(isNewPoly==true){
MarkerOptions markerOptions = new MarkerOptions().position(point).title("Position").snippet("Latitude: "+point.latitude+" , "+"Longitude: "+point.longitude).icon(BitmapDescriptorFactory.fromResource(R.drawable.marker));
map.addMarker(markerOptions);
polylineOptions = new PolylineOptions().color(Color.BLUE).width(3);
points.add(point);
for(int i=0;i<points.size();i++){
polylineOptions.add(points.get(i));
}
map.addPolyline(polylineOptions);
}
for(int i=0;i<points.size();i++){
poly.add(points.get(i));
}
}
});
start.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
isNewPoly=true;
}
});
stop.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
isNewPoly=false;
}
});
}
public static String encode(final List<LatLng> path){
long lastLat = 0;
long lastLng = 0;
final StringBuffer result = new StringBuffer();
for(final LatLng point:path){
long lat = Math.round(point.latitude * 1e5);
long lng = Math.round(point.longitude * 1e5);
long dlat = lat - lastLat;
long dlng = lng - lastLng;
encoded(dlat, result);
encoded(dlng, result);
lastLat = lat;
lastLng = lng;
}
return result.toString();
}
private static void encoded(long v, StringBuffer result){
v = v < 0 ? ~(v<<1) : v<<1;
while(v >= 0x20){
result.append(Character.toChars((int) ((0x20 | (v & 0x1f))+63)));
v >>= 5;
}
result.append(Character.toChars((int) (v + 63)));
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.tambah, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
switch(item.getItemId()){
case R.id.home:
this.finish();
startActivity(new Intent(Tambah.this, Peta.class));
return true;
default:
return super.onOptionsItemSelected(item);
}
}
#Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
}
#Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
#Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
#Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
if I press button start, it make new polyline, and press button stop to stop it, but it's not work. the button stop not warking.
You are currently append all points at once, instead you should use a PolyLine array. Assuming that coordinates1 and coordinates2 are the LatLng[] type of arrays that is previously appended from KML file or some other source. You should write something like below;
int size=3 //determine the size of array.
Polyline[] polyLine;
polyLine = new Polyline[size];
int i =0;
while (i<size)
{
polyLine[i] = map.addPolyline(new PolylineOptions()
.clickable(true)
.add(coordinates1[i],coordinates1[i+1]));
i++;
}
List<LatLng> latLngList = new ArrayList<>();
for (int i = 0; i < arrayList.size(); i++) {
latLngList.add(i, new LatLng(arrayList.get(i).getLocation_lat(), arrayList.get(i).getLocation_lang()));
}
Polyline polyline = googleMaps.addPolyline(new PolylineOptions()
.clickable(true)
.addAll(latLngList)
.width(2).color(Color.BLUE).geodesic(true));
List<LatLng> latLngList = new ArrayList<>();
for (int i = 0; i < arrayList.size(); i++) {
latLngList.add(i, new LatLng(arrayList.get(i).getLocation_lat(), arrayList.get(i).getLocation_lang()));
}
Polyline polyline = mMap.addPolyline(new PolylineOptions()
.clickable(true)
.addAll(latLngList)
.width(2).color(Color.BLUE).geodesic(true));
I am working on google map api v2, and i want to make my marker draggable true,
Simply i want to drag my marker from a location and drop it on anonther one, but it taking time to focus on that marker.
Following is my code, plz suggest me where I'm doing wrong
Activity :
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.widget.Toast;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMarkerDragListener;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
public class DragMarker extends FragmentActivity implements OnMarkerDragListener {
private static GoogleMap map;
#Override
protected void onCreate(Bundle saveInstance) {
super.onCreate(saveInstance);
setContentView(R.layout.activity_test_drag_marker);
map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
map.setOnMarkerDragListener(this);
//map.setOnMapLongClickListener(this);
// map.setOnMapClickListener(this);
CameraPosition INIT = new CameraPosition.Builder().target(new LatLng(19.0222, 72.8666)).zoom(17.5F).bearing(300F) // orientation
.tilt(50F) // viewing angle
.build();
// use map to move camera into position
map.moveCamera(CameraUpdateFactory.newCameraPosition(INIT));
//create initial marker
map.addMarker(new MarkerOptions().position(new LatLng(19.0216, 72.8646)).draggable(true).title("Location").snippet("First Marker")).showInfoWindow();
}
#Override
public void onMarkerDrag(Marker arg0) {
// TODO Auto-generated method stub
}
#Override
public void onMarkerDragEnd(Marker arg0) {
// TODO Auto-generated method stub
LatLng dragPosition = arg0.getPosition();
double dragLat = dragPosition.latitude;
double dragLong = dragPosition.longitude;
Log.i("info", "on drag end :" + dragLat + " dragLong :" + dragLong);
Toast.makeText(getApplicationContext(), "Marker Dragged..!", Toast.LENGTH_LONG).show();
}
#Override
public void onMarkerDragStart(Marker arg0) {
// TODO Auto-generated method stub
}
/*#Override
public void onMapClick(LatLng arg0) {
// TODO Auto-generated method stub
map.animateCamera(CameraUpdateFactory.newLatLng(arg0));
}*/
/*#Override
public void onMapLongClick(LatLng arg0) {
// TODO Auto-generated method stub
//create new marker when user long clicks
map.addMarker(new MarkerOptions().position(arg0).draggable(true));
}*/
}
XML :
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
Put the marker draggable:
Marker perth = mMap.addMarker(new MarkerOptions().position(PERTH).draggable(true));
// Creating MarkerOptions
MarkerOptions options = new MarkerOptions();
// Setting the position of the marker
options.position(point);
//set marker dragable true
options.draggable(true);
I am try to showing current location using android google map api 2, I run this on my phone which is wifi enable.
But it always shows Longitude and Latitude 0.0 , 0.0 .
Here is my code
package com.google.map;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMapLongClickListener;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.map.R;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.app.FragmentManager;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
public class MainActivity extends Activity implements LocationListener{
private GoogleMap googlemap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(isGooglePlay())
{
setContentView(R.layout.activity_main);
setUpMap();
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
if(item.getItemId() == R.id.action_legalnotices)
{
startActivity(new Intent(this, LegalNoticesActivity.class));
}
return super.onOptionsItemSelected(item);
}
private boolean isGooglePlay()
{
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
if(status == ConnectionResult.SUCCESS)
{
return true;
}
else
{
((Dialog)GooglePlayServicesUtil.getErrorDialog(status, this, 10)).show();
Toast.makeText(getApplicationContext(), "Google play is not available.", Toast.LENGTH_LONG).show();
}
return false;
}
#SuppressLint("NewApi") private void setUpMap()
{
if(googlemap == null)
{
googlemap = ((MapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap();
if(googlemap != null)
{
// map code
googlemap.setMyLocationEnabled(true);
googlemap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
LocationManager lo = (LocationManager) getSystemService(LOCATION_SERVICE);
String provider = lo.getBestProvider(new Criteria(),true);
if(provider == null)
{
onProviderDisabled(provider);
}
else
{
onProviderEnabled(provider);
}
Location loc = lo.getLastKnownLocation(provider);
if(loc != null)
{
onLocationChanged(loc);
}
googlemap.setOnMapLongClickListener(onLongClickMapSettings());
}
}
}
private OnMapLongClickListener onLongClickMapSettings() {
// TODO Auto-generated method stub
return new OnMapLongClickListener() {
#Override
public void onMapLongClick(LatLng arg0) {
// TODO Auto-generated method stub
Log.i(arg0.toString(),"Long Click");
}
};
}
#Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
LatLng latlng = new LatLng(location.getLatitude(),location.getLongitude());
googlemap.moveCamera(CameraUpdateFactory.newLatLng(latlng));
googlemap.moveCamera(CameraUpdateFactory.zoomTo(5));
}
#Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
#Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
Location lo = new Location(provider);
LatLng latlng = new LatLng(lo.getLatitude(),lo.getLongitude());
Log.i(latlng.toString(),"Current Location" );
googlemap.moveCamera(CameraUpdateFactory.newLatLng(latlng));
googlemap.moveCamera(CameraUpdateFactory.newLatLngZoom(latlng, 5));
}
#Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
Here is the Log cat value of my android application.
05-07 22:16:31.636: I/lat/lng: (0.0,0.0)(17967): Current Location
Move your Log.i(latlng.toString(),"Current Location" ); code to the onLocationChanged-method, you don't have a location yet in onProviderEnabled.
mMap.setMyLocationEnabled(true); // just add one line it wil work.
this my code and it loade normali but when I change latitude and longitude it not show the corresponding location. I use emulatar to test the programe. I change latitude and longitude by using emulator control.
package com.rumes.gspuse;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
public class Main extends MapActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MapView map=(MapView) findViewById(R.id.map);
map.setBuiltInZoomControls(true);
final MapController controller=map.getController();
LocationManager manager=(LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
LocationListener listner=new LocationListener() {
#Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
#Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
#Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
#Override
public void onLocationChanged(Location location) {
controller.setCenter(new GeoPoint((int)location.getLatitude(), (int)location.getLongitude()));
}
};
manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,listner);
}
#Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
You need latitudeE6 and longitudeE6, that's why you don't see any difference in map!
if(location != null) // avoid crash (check for null)..
controller.setCenter(new GeoPoint((int)(location.getLatitude() * 1E6), (int)(location.getLongitude() * 1E6)));
So i am just trying to get location of user and show it in a toast...but its not working at all...i also tried just to show toast when activity starts but it is not working even at that time
Here's my code
package com.example.alert;
import com.example.alert.CurrentLocation.MyLocationListener;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;
public class ViewAlerters extends Activity{
private Button addButton;
private Button removeButton;
LocationManager lm=(LocationManager)getSystemService(Context.LOCATION_SERVICE);
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.view_alerters);
Toast.makeText( ViewAlerters.this,"Hello",Toast.LENGTH_SHORT).show();
LocationListener ll=new MyLocationListener();
//lm.requestLocationUpdates( LocationManager.GPS_PROVIDER, 5*60*10000, 0, ll);
lm.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, ll);
setUpViews();
}
private void setUpViews() {
Toast.makeText( getApplicationContext(),"Hello",Toast.LENGTH_SHORT).show();
addButton = (Button) findViewById(R.id.add_button);
//alerterText = (TextView) findViewById(R.id.alert_list_text);
removeButton = (Button)findViewById(R.id.remove_button);
addButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(ViewAlerters.this,AddAlerter.class);
startActivity(intent);
}
});
}
/* Class My Location Listener */
public class MyLocationListener implements LocationListener
{
public void onLocationChanged(Location loc)
{
if(loc!=null)
{
double x;
String Text = "My current location is: " +"Latitud = " + loc.getLatitude() +"Longitud = " + loc.getLongitude();
/* cr.moveToFirst();
while(!cr.isAfterLast()) {
al.add(cr.getString(cr.getColumnIndex(dbAdapter.KEY_NAME))); //add the item
cr.moveToNext();
}*/
// lm.addProximityAlert(loc.getLatitude(), loc.getLongitude(), 10009,, intent)
//for loop, alerters retrieving one by one
// x= calcDistance(loc.getLatitude(),loc.getLongitude(),z,y);
// if(x<1){
// Intent myIntent = new Intent(ViewAlerters.this,CallMode.class);
// startActivity(myIntent);
}
}
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
Toast.makeText( getApplicationContext(),"Gps Disabled - #From :Alert Me",Toast.LENGTH_SHORT ).show();
}
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
Toast.makeText( getApplicationContext(),"Gps Enabled - #From :Alert Me",Toast.LENGTH_SHORT).show();
}
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
public double calcDistance(double latA, double longA, double latB, double longB) {
double theDistance = (Math.sin(Math.toRadians(latA)) * Math.sin(Math.toRadians(latB)) + Math.cos(Math.toRadians(latA)) * Math.cos(Math.toRadians(latB)) * Math.cos(Math.toRadians(longA - longB)));
return new Double((Math.toDegrees(Math.acos(theDistance))) * 69.09*1.6093);
}
}
Don't use getApplicationContext:
Toast.makeText( this,"Hello",Toast.LENGTH_SHORT).show();
Refer to this question about the differences in the Contexts: difference and when to use getApplication(), getApplicationContext(), getBaseContext() and someClass.this
Toast.makeText( ViewAlerters.this,"Hello",Toast.LENGTH_SHORT).show();