Android谷歌地图v2 API突然停止工作?
更新 我和我的同事试过N6。成功了。所以我买了一个新的N6。我安装播放服务。。它失败了 我整天都在做这件事。昨天一整天它都运转得很好。我所能记得的就是gradle让我交换网络(安全)来下载一些东西。大约一个小时后,我去建造。。娜达。回到昨晚的检查,娜达。它适用于我的个人电话,但不适用于Nexus6。见鬼,我甚至把######手机闪到了5.1 nexus图像上。娜达。清除所有缓存的gradle文件,旋转min SDK编号。没有什么。哦,谷歌搜索了几个小时 我建造、运行没有问题。使用我的地图“崩溃”导航到活动。虽然只在nexus上,但我的Note4没有崩溃。问题不是空指针,而是Android谷歌地图v2 API突然停止工作?,android,google-maps,android-maps-v2,Android,Google Maps,Android Maps V2,更新 我和我的同事试过N6。成功了。所以我买了一个新的N6。我安装播放服务。。它失败了 我整天都在做这件事。昨天一整天它都运转得很好。我所能记得的就是gradle让我交换网络(安全)来下载一些东西。大约一个小时后,我去建造。。娜达。回到昨晚的检查,娜达。它适用于我的个人电话,但不适用于Nexus6。见鬼,我甚至把######手机闪到了5.1 nexus图像上。娜达。清除所有缓存的gradle文件,旋转min SDK编号。没有什么。哦,谷歌搜索了几个小时 我建造、运行没有问题。使用我的地图“崩溃”
06-23 15:01:21.414 19516-19516/? W/ResourcesManager﹕ Asset path '/system/framework/com.android.media.remotedisplay.jar' does not exist or contains no resources.
06-23 15:01:21.414 19516-19516/? W/ResourcesManager﹕ Asset path '/system/framework/com.android.location.provider.jar' does not exist or contains no resources.
下面全是
06-23 15:01:14.982 19516-19535/xxxx.xxxx.xxxx.mobility I/Adreno﹕ EGLInit: QTI Build: 01/29/15, 1bccc5d, I0ba6dce82d
06-23 15:01:14.990 19516-19535/xxxx.xxxx.xxxx.mobility I/OpenGLRenderer﹕ Initialized EGL, version 1.4
06-23 15:01:14.997 19516-19535/xxxx.xxxx.xxxx.mobility D/OpenGLRenderer﹕ Enabling debug mode 0
06-23 15:01:16.733 19516-19526/? I/art﹕ Ignoring second debugger -- accepting and dropping
06-23 15:01:21.407 19516-19516/? I/zzy﹕ Making Creator dynamically
06-23 15:01:21.414 19516-19516/? W/ResourcesManager﹕ Asset path '/system/framework/com.android.media.remotedisplay.jar' does not exist or contains no resources.
06-23 15:01:21.414 19516-19516/? W/ResourcesManager﹕ Asset path '/system/framework/com.android.location.provider.jar' does not exist or contains no resources.
06-23 15:01:21.443 19516-19516/? I/Google Maps Android API﹕ Google Play services client version: 7571000
06-23 15:01:21.452 19516-19516/? I/Google Maps Android API﹕ Google Play services package version: 7574430
06-23 15:01:21.845 19516-19516/? D/AndroidRuntime﹕ Shutting down VM
06-23 15:01:21.846 19516-19516/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: xxxx.xxxx.xxxx.mobility, PID: 19516
java.lang.NullPointerException: Attempt to invoke virtual method 'double android.location.Location.getLatitude()' on a null object reference
at xxxx.xxxx.xxxx.mobility.Map.MapPaneActivity.onMapReady(MapPaneActivity.java:109)
at com.google.android.gms.maps.MapFragment$zza$1.zza(Unknown Source)
at com.google.android.gms.maps.internal.zzm$zza.onTransact(Unknown Source)
at android.os.Binder.transact(Binder.java:380)
at com.google.android.gms.maps.internal.ba.a(SourceFile:82)
at com.google.maps.api.android.lib6.d.fz.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
删掉大部分包名。权限位于顶部
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="xcv.qwe.xxxxx.mobility"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<permission
android:name="xcv.qwe.xxxxx.mobility.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="xcv.qwe.xxxxx.mobility.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".StartSplashActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/title_activity_start_splash" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="xxxxx"
<activity
android:name=".StartSplashActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/title_activity_start_splash" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<receiver
android:name="xxxxx"
android:enabled="true" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" >
</action>
</intent-filter>
</receiver>
<receiver
android:name="xxxxxr"
android:enabled="true" >
</receiver>
<receiver
android:name="xxxxx"
android:enabled="true" >
<intent-filter>
<action android:name="local.transition.initialize" />
<action android:name="local.transition.exited_geofence" />
<action android:name="local.transition.stopped_moving" />
<action android:name="local.transition.stop_tracking" />
</intent-filter>
</receiver>
<receiver android:name="xxxxx" >
<intent-filter>
<action android:name="android.intent.action.ACTION_BATTERY_LOW" />
<action android:name="android.intent.action.ACTION_BATTERY_OKAY" />
</intent-filter>
</receiver>
<service
android:name="xxxxx"
android:enabled="true" >
</service>
<service android:name="xxxxx" >
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator" />
</intent-filter>
<meta-data
android:name="android.accounts.AccountAuthenticator"
android:resource="@xml/authenticator" />
</service>
<service
android:name="xxxxx"
android:enabled="true"
android:exported="false" >
</service>
<service
android:name="xxxxxe"
android:enabled="true"
android:exported="false" >
</service>
<service
android:name="xxxxx"
android:enabled="true"
android:exported="false" >
</service>
<service
android:name="xxxxx"
android:exported="true"
android:process=":sync" >
<intent-filter>
<action android:name="android.content.SyncAdapter" />
</intent-filter>
<meta-data
android:name="android.content.SyncAdapter"
android:resource="@xml/syncadapter" />
</service>
<provider
android:name="xxxxx"
android:authorities="xxxxx"
android:exported="false"
android:syncable="true" />
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
</activity>
<activity
android:name="xxxxx.MainActivity"
android:label="@string/app_name" >
</activity>
<activity
android:name=".InformedConsentActivity"
android:label="@string/title_activity_informed_consent"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" >
</activity>
<activity
android:name=".calendar.CalendarScrapeActivity"
android:label="@string/title_activity_calendar_scrape"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" >
</activity>
<activity
android:name=".calendar.CalendarViewerActivity"
android:label="@string/title_activity_calendar_viewer"
android:theme="@style/Theme.AppCompat.Light"
>
</activity>
<activity
android:name=".Map.MapPaneActivity"
android:label="@string/title_activity_calendar_viewer"
android:theme="@style/Theme.AppCompat.Light"
>
</activity>
" />
<receiver
android:name="xxxxx"
android:enabled="true" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" >
</action>
</intent-filter>
</receiver>
<receiver
android:name="xxxxx"
android:enabled="true" >
<intent-filter>
<action android:name="xxxxx" />
</intent-filter>
</receiver>
<receiver
android:name="xxxxx"
android:enabled="true" >
<intent-filter>
<action android:name="local.transition.initialize" />
<action android:name="local.transition.exited_geofence" />
<action android:name="local.transition.stopped_moving" />
<action android:name="local.transition.stop_tracking" />
</intent-filter>
</receiver>
<receiver android:name="xxxxx" >
<intent-filter>
<action android:name="android.intent.action.ACTION_BATTERY_LOW" />
<action android:name="android.intent.action.ACTION_BATTERY_OKAY" />
</intent-filter>
</receiver>
<service
android:name="xxxxx"
android:enabled="true" >
</service>
<service android:name="xxxxx" >
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator" />
</intent-filter>
<meta-data
android:name="android.accounts.AccountAuthenticator"
android:resource="@xml/authenticator" />
</service>
<service
android:name="xxxxx"
android:exported="true"
android:process=":sync" >
<intent-filter>
<action android:name="android.content.SyncAdapter" />
</intent-filter>
<meta-data
android:name="android.content.SyncAdapter"
android:resource="@xml/syncadapter" />
</service>
<provider
android:name="xxxxtracker.smap.StubContentProvider"
android:authorities="xxxxtracker.provider"
android:exported="false"
android:syncable="true" />
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
</activity>
<activity
android:name="xxxxtracker.MainActivity"
android:label="@string/app_name" >
</activity>
<activity
android:name=".InformedConsentActivity"
android:label="@string/title_activity_informed_consent"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" >
</activity>
<activity
android:name=".calendar.CalendarScrapeActivity"
android:label="@string/title_activity_calendar_scrape"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" >
</activity>
<activity
android:name=".calendar.CalendarViewerActivity"
android:label="@string/title_activity_calendar_viewer"
android:theme="@style/Theme.AppCompat.Light"
>
</activity>
<activity
android:name=".Map.MapPaneActivity"
android:label="@string/title_activity_calendar_viewer"
android:theme="@style/Theme.AppCompat.Light"
>
</activity>
</application>
Java代码。它主要是带有几个单击侦听器的示例代码。我确实把地图改成了混合的,从样本。。。编辑我不认为这是谷歌的样本,现在我看到的问题
package xxx.xxx.xxx.mobility.Map;
import android.app.Activity;
import android.content.Intent;
import android.location.Address;
import android.location.Criteria;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.Toast;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import xxx.xxx.xxx.mobility.R;
import xxx.xxx.xxx.mobility.calendar.CalendarConstants;
public class MapPaneActivity extends Activity implements OnMapReadyCallback, GoogleMap.OnMapClickListener, GoogleMap.OnMapLongClickListener, Spinner.OnItemSelectedListener {
final static int MAP_MAX_RESULTS = 10;
final static String TAG = "MapPaneActivity";
private Spinner map_selection_spinner;
private ArrayAdapter<String> mMapAddressAdapter;
private LatLng mLatLng;
private String mCurrentSelection = "";
Button submit_map_button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map_pane);
map_selection_spinner = (Spinner) findViewById(R.id.map_selection_spinner);
submit_map_button = (Button) findViewById(R.id.submit_map_button);
MapFragment mapFragment = (MapFragment) getFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
map_selection_spinner.setOnItemSelectedListener(this);
/*
* The submit button will take the currently selected label from the spinner
* and return to the calling activity.
*/
submit_map_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Bundle bundle = new Bundle();
bundle.putString(CalendarConstants.mapDataKey, mLatLng+CalendarConstants.divider+ mCurrentSelection);
Intent intent = new Intent();
intent.putExtras(bundle);
setResult(RESULT_OK, intent);
finish();
}
});
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int pos,long id) {
if (mMapAddressAdapter != null) {
submit_map_button.setEnabled(true);
mCurrentSelection = mMapAddressAdapter.getItem(pos);
// Toast.makeText(getApplicationContext(), mCurrentSelection, Toast.LENGTH_LONG).show();
}
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
@Override
public void onMapReady(GoogleMap map) {
map.setMyLocationEnabled(true);
map.setOnMapClickListener(this);
map.setOnMapLongClickListener(this);
/*
* Set the map to our cuurent location
*/
map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, true);
Location myLocation = locationManager.getLastKnownLocation(provider);
double latitude = myLocation.getLatitude();
double longitude = myLocation.getLongitude();
LatLng latLng = new LatLng(latitude, longitude);
map.moveCamera(CameraUpdateFactory.newLatLng(latLng));
// Zoom in the Google Map
map.animateCamera(CameraUpdateFactory.zoomTo(17));
map.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)).title(getResources().getString(R.string.your_local)));
}
/**
* Handles the clicking of the map fragment.
* This will mark a location and kick off populating the
* spinner with addresses
* @param latLng
*/
@Override
public void onMapClick(LatLng latLng) {
mLatLng = latLng;
// Toast.makeText(getApplicationContext(), "Clicked at.. " + mLatLng, Toast.LENGTH_LONG).show();
List<Address> addressList;
Geocoder geocoder = new Geocoder(getApplicationContext());
double latitude = mLatLng.latitude;
double longitude = mLatLng.longitude;
try {
addressList = geocoder.getFromLocation(latitude, longitude, MAP_MAX_RESULTS);
for(Address address : addressList){
Log.d(TAG,address+" is at "+mLatLng);
}
}
catch (IOException exception){
Log.e(TAG, "Got an IO exeption!");
}
}
@Override
public void onMapLongClick(LatLng latLng) {
onMapClick(latLng);
}
}
包xxx.xxx.xxx.mobility.Map;
导入android.app.Activity;
导入android.content.Intent;
导入android.location.Address;
导入android.location.Criteria;
导入android.location.Geocoder;
导入android.location.location;
导入android.location.LocationManager;
导入android.os.Bundle;
导入android.text.TextUtils;
导入android.util.Log;
导入android.view.view;
导入android.widget.AdapterView;
导入android.widget.ArrayAdapter;
导入android.widget.Button;
导入android.widget.Spinner;
导入android.widget.Toast;
导入com.google.android.gms.maps.CameraUpdateFactory;
导入com.google.android.gms.maps.GoogleMap;
导入com.google.android.gms.maps.MapFragment;
导入com.google.android.gms.maps.OnMapReadyCallback;
导入com.google.android.gms.maps.model.LatLng;
导入com.google.android.gms.maps.model.MarkerOptions;
导入java.io.IOException;
导入java.util.ArrayList;
导入java.util.List;
导入xxx.xxx.xxx.mobility.R;
导入xxx.xxx.xxx.mobility.calendar.CalendarConstants;
公共类MapPaneActivity扩展了活动在MapReadyCallback、GoogleMap.OnMapClickListener、GoogleMap.OnMapLongClickListener、Spinner.OnItemSelectedListener上的实现{
最终静态int-MAP_MAX_结果=10;
最终静态字符串标记=“MapPaneActivity”;
私有微调器映射\选择\微调器;
专用阵列适配器;
私人车床;
私有字符串mCurrentSelection=“”;
按钮提交\地图\按钮;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u map\u窗格);
map\u selection\u微调器=(微调器)findViewById(R.id.map\u selection\u微调器);
提交地图按钮=(按钮)findViewById(R.id.submit地图按钮);
MapFragment MapFragment=(MapFragment)getFragmentManager()
.findFragmentById(R.id.map);
getMapAsync(这个);
映射\u选择\u微调器。setOnItemSelectedListener(此);
/*
*“提交”按钮将从微调器中获取当前选定的标签
*然后返回调用活动。
*/
submit\u map\u button.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图){
Bundle=新Bundle();
bundle.putString(CalendarConstants.mapDataKey,mLatLng+CalendarConstants.divider+mCurrentSelection);
意图=新意图();
意向。额外支出(捆绑);
设置结果(结果正常,意图);
完成();
}
});
}
@凌驾
已选择公共位置(AdapterView父项、视图、整数位置、长id){
if(mMapAddressAdapter!=null){
提交地图按钮。setEnabled(真);
mCurrentSelection=mMapAddressAdapter.getItem(pos);
//Toast.makeText(getApplicationContext(),mCurrentSelection,Toast.LENGTH_LONG).show();
}
}
@凌驾
未选择公共无效(AdapterView AdapterView){
}
@凌驾
已于4月1日公开作废(谷歌地图){
map.setMyLocationEnabled(true);
map.setOnMapClickListener(this);
map.setOnMapLongClickListener(此);
/*
*将地图设置到我们所在的位置
*/
setMapType(GoogleMap.map\u TYPE\u HYBRID);
LocationManager LocationManager=(LocationManager)getSystemService(LOCATION\u服务);
标准=新标准();
字符串提供程序=locationManager.getBestProvider(条件为true);
Location myLocation=locationManager.getLastKnownLocation(提供者);
双纬度=myLocation.getLatitude();
double longitude=myLocation.getLongitude();
LatLng LatLng=新LatLng(纬度、经度);
地图移动摄像机(CameraUpdateFactory.newLatLng(latLng));
//放大谷歌地图
map.animateCamera(CameraUpdateFactory.zoomTo(17));
map.addMarker(newmarkeroptions().position(newlatlng(纬度、经度)).title(getResources().getString(R.string.your_local));
}
/**
*处理贴图片段的单击。
*这将标记一个位置并开始填充
*带地址的微调器
*@param-latLng
*/
@凌驾
公共无效的点击(LatLng LatLng){
mLatLng=latLng;
//Toast.makeText(getApplicationContext(),“单击..”+mLatLng,Toast.LENGTH_LONG).show();
列表地址列表;
Geocoder Geocoder=新的Geocoder(getApplicationContext());
双纬度=最小纬度;
双经度=mLatLng.longitude;
试一试{
地址
package xxx.xxx.xxx.mobility.Map;
import android.app.Activity;
import android.content.Intent;
import android.location.Address;
import android.location.Criteria;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.Toast;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import xxx.xxx.xxx.mobility.R;
import xxx.xxx.xxx.mobility.calendar.CalendarConstants;
public class MapPaneActivity extends Activity implements OnMapReadyCallback, GoogleMap.OnMapClickListener, GoogleMap.OnMapLongClickListener, Spinner.OnItemSelectedListener {
final static int MAP_MAX_RESULTS = 10;
final static String TAG = "MapPaneActivity";
private Spinner map_selection_spinner;
private ArrayAdapter<String> mMapAddressAdapter;
private LatLng mLatLng;
private String mCurrentSelection = "";
Button submit_map_button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map_pane);
map_selection_spinner = (Spinner) findViewById(R.id.map_selection_spinner);
submit_map_button = (Button) findViewById(R.id.submit_map_button);
MapFragment mapFragment = (MapFragment) getFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
map_selection_spinner.setOnItemSelectedListener(this);
/*
* The submit button will take the currently selected label from the spinner
* and return to the calling activity.
*/
submit_map_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Bundle bundle = new Bundle();
bundle.putString(CalendarConstants.mapDataKey, mLatLng+CalendarConstants.divider+ mCurrentSelection);
Intent intent = new Intent();
intent.putExtras(bundle);
setResult(RESULT_OK, intent);
finish();
}
});
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int pos,long id) {
if (mMapAddressAdapter != null) {
submit_map_button.setEnabled(true);
mCurrentSelection = mMapAddressAdapter.getItem(pos);
// Toast.makeText(getApplicationContext(), mCurrentSelection, Toast.LENGTH_LONG).show();
}
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
@Override
public void onMapReady(GoogleMap map) {
map.setMyLocationEnabled(true);
map.setOnMapClickListener(this);
map.setOnMapLongClickListener(this);
/*
* Set the map to our cuurent location
*/
map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, true);
Location myLocation = locationManager.getLastKnownLocation(provider);
double latitude = myLocation.getLatitude();
double longitude = myLocation.getLongitude();
LatLng latLng = new LatLng(latitude, longitude);
map.moveCamera(CameraUpdateFactory.newLatLng(latLng));
// Zoom in the Google Map
map.animateCamera(CameraUpdateFactory.zoomTo(17));
map.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)).title(getResources().getString(R.string.your_local)));
}
/**
* Handles the clicking of the map fragment.
* This will mark a location and kick off populating the
* spinner with addresses
* @param latLng
*/
@Override
public void onMapClick(LatLng latLng) {
mLatLng = latLng;
// Toast.makeText(getApplicationContext(), "Clicked at.. " + mLatLng, Toast.LENGTH_LONG).show();
List<Address> addressList;
Geocoder geocoder = new Geocoder(getApplicationContext());
double latitude = mLatLng.latitude;
double longitude = mLatLng.longitude;
try {
addressList = geocoder.getFromLocation(latitude, longitude, MAP_MAX_RESULTS);
for(Address address : addressList){
Log.d(TAG,address+" is at "+mLatLng);
}
}
catch (IOException exception){
Log.e(TAG, "Got an IO exeption!");
}
}
@Override
public void onMapLongClick(LatLng latLng) {
onMapClick(latLng);
}
}
Location myLocation = locationManager.getLastKnownLocation(provider);
double latitude = myLocation.getLatitude();