我正在制作我的学期项目车辆跟踪使用Android地图。我正在寻求帮助。我通过短信从车辆接收位置,我想要的是显示位置或更新地图,当我得到新的短信。
我想问一下如何在一段时间后或在收到新短信时更新地图。
例如12.3245678, 52.333333312.3245689, 52.333333412.3245680, 52.333333512.3245682, 52.3333336
我知道location.getlangitude()
和位置侦听器,我认为它只使用getlanitude()和getlantiitude()为GPS传输器和网络提供商更新地图。
但是如何手动设置GeoPoint和更新位置监听器。或者以如何更新地图为例数据库中有位置数据这对我也有帮助
public class SMSNotificationListener extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Here you can extract the intent extra ( lat , longs )
// Even you can check some message code to identify valid message
// Can call some different MapDisplayActivity with lat , longs
// in Intent.putExtra(...)
}
}
在AndroidManifest中添加接收器
<receiver android:name=".SMSNotificationListener">
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
</receiver>
现在在MapDisplayActivity -
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
mapView = (MapView) findViewById(R.id.mapview);
setMaptoProvidedLocation();
}
/**
* Setting Google Map to provided location
*/
private void setMaptoProvidedLocation() {
Intent intent = getIntent();
LAT = intent.getIntExtra(DisplayActivity.LAT, DisplayActivity.DEF_LAT);
LNG = intent.getIntExtra(DisplayActivity.LNG, DisplayActivity.DEF_LNG);
mapView.setBuiltInZoomControls(true);
mapView.setSatellite(true);
mapController = mapView.getController();
mapController.setZoom(ZOOM_LEVEL - ZOOM_LEVEL / 2);
GeoPoint vehicleLocation = new GeoPoint(LAT, LNG);
mapController.animateTo(vehicleLocation);
// You can also add map overlays ...
}
//If MapDisplayActivity is in forground and we want to update the new location
@Override
public void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
Log.d("MapActivity","Got new Data again");
setMaptoProvidedLocation(false);
}
好的,你在这里做了很多事情。
-
要拦截SMS消息,您需要侦听这些。参见:Android - Listen For Incoming SMS Messages
-
要基于位置数据制作带有标记的地图,请使用google maps api V.2。这将告诉你所有你需要知道的关于从位置数据制作带有标记的地图。
-
如果你想在一个固定的时间间隔从数据库更新地图,我建议做一个asynctask或定时器,检查在数据库中的更新在所需的固定时间间隔。