-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMap.java
More file actions
55 lines (49 loc) · 2.34 KB
/
Map.java
File metadata and controls
55 lines (49 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
########################################################################
# Copyright (C) 2013 Panagiotis Kritikakos <panoskrt@gmail.com> #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
########################################################################
**/
package com.panoskrt.map;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationManager;
import android.net.Uri;
import android.widget.Toast;
public class Map {
private Context context;
private String destination;
public Map(Context context, String destination) {
this.context = context;
this.destination = destination;
}
public void openMap() {
double lat = 0;
double lon = 0;
try {
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
lat = location.getLatitude();
lon = location.getLongitude();
Toast.makeText(context.getApplicationContext(), "Getting route...", Toast.LENGTH_SHORT).show();
} catch (Exception ex) {
Toast.makeText(context.getApplicationContext(), "Error while getting GPS signal.", Toast.LENGTH_SHORT).show();
}
String address = "http://maps.google.com/maps?saddr=" + lat + "," + lon + "&daddr=" + this.destination;
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(address));
context.startActivity(intent);
}
}