- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在开发一个应用程序,因为我想在打开通知时显示 map ,我成功收到了通知,但是当我打开通知时没有打开具有该经纬度值的 map 。
GCMIntent 服务类
public class GcmIntentService extends IntentService{
Context context;
public static int notify_no=0;
//System.currentTimeMillis();
private NotificationManager mNotificationManager;
NotificationCompat.Builder builder;
public static final String TAG = "GCM NOTIFICATION";
public GcmIntentService() {
super("GcmIntentService");
// TODO Auto-generated constructor stub
}
@Override
protected void onHandleIntent(Intent intent) {
// TODO Auto-generated method stub
Bundle extras = intent.getExtras();
String msg = intent.getStringExtra("message");
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
String messageType = gcm.getMessageType(intent);
if (!extras.isEmpty()) {
if (GoogleCloudMessaging.
MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
// sendNotification(RegIdDTO.REG_ID,"Send error: " + extras.toString());
sendNotification(this,msg);
} else if (GoogleCloudMessaging.
MESSAGE_TYPE_DELETED.equals(messageType)) {
// sendNotification(RegIdDTO.REG_ID,"Deleted messages on server: " +
// extras.toString());
sendNotification(this,msg);
// If it's a regular GCM message, do some work.
} else if (GoogleCloudMessaging.
MESSAGE_TYPE_MESSAGE.equals(messageType)) {
// This loop represents the service doing some work.
for (int i=0; i<5; i++) {
Log.i(TAG, "Working... " + (i+1)
+ "/5 @ " + SystemClock.elapsedRealtime());
try {
Thread.sleep(500);
} catch (InterruptedException e) {
}
}
Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());
// Post notification of received message.
//sendNotification("Received: " + extras.toString());
// sendNotification(RegIdDTO.REG_ID,msg);
sendNotification(this,msg);
Log.i(TAG, "Received: " + extras.toString());
}
}
GcmBroadcastReceiver.completeWakefulIntent(intent);
}
private static void sendNotification(Context context,String message) {
int icon = R.drawable.ic_stat_gcm;
long when = System.currentTimeMillis();
NotificationCompat.Builder nBuilder;
Uri alarmSound = RingtoneManager
.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
nBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("header")
.setLights(Color.BLUE, 500, 500).setContentText(message)
.setAutoCancel(true).setTicker("Notification from Traffic")
.setVibrate(new long[] { 100, 250, 100, 250, 100, 250 })
.setSound(alarmSound);
String consumerid = null;
Integer position = null;
// write your click event here
Intent resultIntent = new Intent(context, ShowMapActivity.class);
resultIntent.putExtra("message", message);
// resultIntent.setData(Uri.parse("content://"+when));
PendingIntent resultPendingIntent = PendingIntent.getActivity(context,
notify_no, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
// Show the max number of notifications here
if (notify_no < 9) {
notify_no = notify_no + 1;
} else {
notify_no = 0;
}
nBuilder.setContentIntent(resultPendingIntent);
NotificationManager nNotifyMgr = (NotificationManager) context
.getSystemService(context.NOTIFICATION_SERVICE);
nNotifyMgr.notify(notify_no + 2, nBuilder.build());
}
}
显示 map 类
public class ShowMapActivity extends FragmentActivity implements LocationListener {
GoogleMap _googleMap;
LatLng myPosition;
LocationManager locationManger;
TextView addressTextView,cTimeTextView;
JSONObject json;
GcmIntentService serv;
Context mContext;
Intent noticeIntent = getIntent();
String lat;
String lng;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_map);
//addressTextView = (TextView)findViewById(R.id.addressId);
//cTimeTextView = (TextView)findViewById(R.id.ctimeId);
String message = noticeIntent.getExtras().getString("message");
try {
json = new JSONObject(message);
lat = json.getString("lat");
Log.e("LLOONNGG", ""+lat);
lng = json.getString("lng");
Log.e("LLOONNGG", ""+lng);
String adr = json.getString("address");
addressTextView.setText(adr);
String ctime = json.getString("ctime");
cTimeTextView.setText(ctime);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
_googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(
R.id.map)).getMap();
LocationManager service = (LocationManager)getSystemService(LOCATION_SERVICE);
boolean enableGPS = service.isProviderEnabled(LocationManager.GPS_PROVIDER);
boolean enableWiFi= service.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if(!enableGPS || !enableWiFi){
Toast.makeText(ShowMapActivity.this, "GPS signal not found", Toast.LENGTH_LONG).show();
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
}
locationManger = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = service.getBestProvider(criteria, true);
service.requestLocationUpdates(provider, 0, 0, this);
if(_googleMap==null){
Toast.makeText(getApplicationContext(), "Google Map Not Available", Toast.LENGTH_LONG).show();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.show_map, menu);
return true;
}
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
//locationManger.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
_googleMap.clear();
ArrayList<HashMap<String, String>> arl = (ArrayList<HashMap<String, String>>)
getIntent().getSerializableExtra("arrayList");
/*if(location!=null){
double latitude = location.getLatitude();
double langitude = location.getLongitude();
LatLng latlang = new LatLng(latitude, langitude);
//LatLngBounds curScreen =
_googleMap.getProjection().getVisibleRegion().latLngBounds;
//curScreen.contains(latlang);
myPosition = new LatLng(latitude, langitude);
// Show only Current Location
_googleMap.moveCamera(CameraUpdateFactory.newLatLng(myPosition));
_googleMap.addMarker(new
MarkerOptions().position(myPosition).title("start"));
}*/
if ( !lat.trim().equals("") && !lng.trim().equals("") ) {
double Hlat = Double.parseDouble(lat.trim());
double Hlong= Double.parseDouble(lng.trim());
LatLng dabaseLocations =new LatLng(Hlat, Hlong);
Log.e("LLAATTAA", ""+Hlat);
Log.e("LLOONNGG", ""+Hlong);
// Show current location with database locations
_googleMap.moveCamera(CameraUpdateFactory.newLatLng(dabaseLocations));
_googleMap.addMarker(new
MarkerOptions().position(dabaseLocations).title("start"));
}
}
@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
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
serv=new GcmIntentService();
//serv.CancelNotification(getApplicationContext());
}
}
我的日志
03-06 13:03:40.187: E/AndroidRuntime(18546): java.lang.RuntimeException: Unable to start activity
日志
ComponentInfo{com.technowellServices.traffic/com.technowellServices.traffic.ShowMapActivity}:
java.lang.NullPointerException
03-06 13:03:40.187: E/AndroidRuntime(18546): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1728)
03-06 13:03:40.187: E/AndroidRuntime(18546): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1747)
03-06 13:03:40.187: E/AndroidRuntime(18546): at
android.app.ActivityThread.access$1500(ActivityThread.java:155)
03-06 13:03:40.187: E/AndroidRuntime(18546): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:993)
03-06 13:03:40.187: E/AndroidRuntime(18546): at
android.os.Handler.dispatchMessage(Handler.java:130)
03-06 13:03:40.187: E/AndroidRuntime(18546): at android.os.Looper.loop(SourceFile:351)
03-06 13:03:40.187: E/AndroidRuntime(18546): at
android.app.ActivityThread.main(ActivityThread.java:3814)
03-06 13:03:40.187: E/AndroidRuntime(18546): at
java.lang.reflect.Method.invokeNative(Native Method)
03-06 13:03:40.187: E/AndroidRuntime(18546): at j
ava.lang.reflect.Method.invoke(Method.java:538)
03-06 13:03:40.187: E/AndroidRuntime(18546): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
03-06 13:03:40.187: E/AndroidRuntime(18546): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:659)
03-06 13:03:40.187: E/AndroidRuntime(18546): at dalvik.system.NativeStart.main(Native
Method)
03-06 13:03:40.187: E/AndroidRuntime(18546): Caused by: java.lang.NullPointerException
03-06 13:03:40.187: E/AndroidRuntime(18546): at
com.technowellServices.traffic.ShowMapActivity.onCreate(ShowMapActivity.java:66)
03-06 13:03:40.187: E/AndroidRuntime(18546): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1082)
03-06 13:03:40.187: E/AndroidRuntime(18546): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1692)
最佳答案
你不能这样称呼
Intent noticeIntent = getIntent();
在 onCreate() 方法之前。
你应该把它放在 onCreate() 方法中。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_map);
Intent noticeIntent = getIntent();
// ...
}
改变这个从
String message = noticeIntent.getExtras().getString("message");
到
String message = noticeIntent.getStringExtras("message");
关于android - 打开通知时如何在 map 上显示经纬度点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22217838/
我对纬度和经度有疑问。当我想获取坐标时,只有 24 个 API 检索坐标。其他人没有。不知道为什么 我正在使用 GPSTracker 服务 public Location getLocation()
我有一个表(DB2 数据库),其中包含城市信息和相应的经纬度以及与城市相关的许多其他信息。我的要求是: 我的应用程序的输入将是纬度和经度,它们可能是或许多不是存储在数据库中的精确纬度和经度。我需要借助
我在经度和纬度上有一个位置 (A)。 我有一条线段,起点(B)和终点(C)在经度和纬度上。 我试图计算的是从 A 到 BC 线的最短距离。 换句话说,从 A 到最近点(在 BC 线上)的距离(以米为单
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,
这个问题在这里已经有了答案: Find nearest latitude/longitude with an SQL query (18 个答案) 关闭 6 年前。 我正在尝试编写一个在某个位置附近
我正在尝试将 Yelp 的 API 与纬度/经度位置结合使用。我使用了 yelp 给出的 javascript 代码,它基本上有一个参数数组,并像这样将值插入其中: parameters.push([
我有一大组纬度和经度需要存储在 MySQL 数据库中。我正在阅读有关要使用的字段类型的相互矛盾的建议。 数据的一个例子是... Lat | Long -----------------
在我的应用程序中,我通过以特定时间间隔从服务器获取他们的位置(纬度和经度)来显示其他人的位置。 获取后,我必须删除所有注释并删除基于服务器数据的新注释。 但它看起来非常低效,因为当我们以前存在相同用户
我正在尝试将鼠标在谷歌地图上的位置转换为 LatLng 对象。我看到很多关于通过谷歌地图“点击”事件等获取位置的帖子,如下所示: google.maps.event.addListener(map,
我的 SQLite 数据库中存储了经纬度数据,我想获取与我输入的参数最近的位置(例如,我当前的位置 - 纬度/经度等)。 我知道这在 MySQL 中是可能的,并且我已经进行了相当多的研究,认为 SQL
伙计们,我在我的 Android 应用程序中实现了谷歌地图,并开始创建一个标记,我在 map 中间放置了一个标记图像。现在,我希望每当用户拖动 map 时,我都能得到 map 中心的位置(我放置图像的
我正在实现 GPS 跟踪器以从 http://www.androidhive.info/2012/07/android-gps-location-manager-tutorial/ 获取经度和纬度.
我有一个多边形形状文件(可下载 here ),我想从中创建一个包含 3 列的 data.frame ,其中包含: 多边形 ID 质心纬度 质心经度 来自这个答案here ,我知道以 Formal Cl
有没有办法使用facebook api以(纬度和经度格式)获取用户的位置? 我能够获得位置名称和其他属性,但不能获得该地点的经纬度。 javascript中是否有相同的API。 最佳答案 如果您有用户
在我的“原生”Android 应用程序中,我试图计算 map 上两个位置之间以英尺和/或米(如乌鸦飞翔)为单位的距离。理想情况下,会有一种方法将两个 LatLng 值(因为这是我随时可用的)作为输入并
我想使用 Google API 获取 GPS 位置。 我的代码: mGoogleApiClient = new GoogleApiClient.Builder(this)
这个问题在这里已经有了答案: How to calculate the latlng of a point a certain distance away from another? (6 个答案)
我是一名优秀的程序员,十分优秀!