Google maps 我正试图展示附近的固定地点

Google maps 我正试图展示附近的固定地点,google-maps,Google Maps,这是我推荐的链接,但当我在搜索框中输入atm或学校等名称时,会出现错误 在googleMap.clear()上放置displaytask.java 空指针异常 我试了另一个密码 这是 私有GoogleAppClient客户端; @凌驾 创建时受保护的void(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity\u邻居); //获取SupportMapF

这是我推荐的链接,但当我在搜索框中输入atm或学校等名称时,会出现错误

在googleMap.clear()上放置displaytask.java 空指针异常

我试了另一个密码

这是

私有GoogleAppClient客户端;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u邻居);
//获取SupportMapFragment,并在地图准备好使用时收到通知。
/*SupportMapFragment mapFragment=(SupportMapFragment)getSupportFragmentManager()
.findFragmentById(R.id.map);
getMapAsync(这个);
*/
//位置类型数组
mPlaceType=getResources().getStringArray(R.array.place\u类型);
//地名类型名称数组
mPlaceTypeName=getResources().getStringArray(R.array.place\u type\u name);
//使用位置类型数组创建数组适配器
//填充微调器的步骤
ArrayAdapter=新的ArrayAdapter(这是android.R.layout.simple\u spinner\u dropdown\u项,mPlaceTypeName);
//获取对微调器的引用
mSprPlaceType=(微调器)findViewById(R.id.spr\u place\u type);
//在微调器上设置适配器以设置放置类型
mSprPlaceType.setAdapter(适配器);
按钮btnFind;
//获取“查找”按钮的引用
btnFind=(按钮)findviewbyd(R.id.btn\u find);
//获取Google Play可用性状态
int status=GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());
如果(status!=ConnectionResult.SUCCESS){//Google Play服务不可用
int requestCode=10;
Dialog Dialog=GooglePlayServicesUtil.getErrorDialog(状态、此、请求代码);
dialog.show();
}其他{//Google Play服务可用
//获取对SupportMapFragment的引用
SupportMapFragment fragment=(SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
//获取谷歌地图
gragment.getMapAsync(this);
//在Google地图中启用MyLocation
//从系统服务位置\u服务获取LocationManager对象
LocationManager LocationManager=(LocationManager)getSystemService(LOCATION\u服务);
//创建条件对象以检索提供程序
标准=新标准();
//获取最佳提供商的名称
字符串提供程序=locationManager.getBestProvider(条件为true);
//从GPS获取当前位置
if(ActivityCompat.checkSelfPermission(this,android.Manifest.permission.ACCESS\u FINE\u LOCATION)!=PackageManager.permission\u已授予和&ActivityCompat.checkSelfPermission(this,android.Manifest.permission.ACCESS\u LOCATION)!=PackageManager.permission\u已授予){
考虑到呼叫
//ActivityCompat#请求权限
//在此处请求缺少的权限,然后覆盖
//public void onRequestPermissionsResult(int-requestCode,字符串[]权限,
//int[]格兰特结果)
//处理用户授予权限的情况。请参阅文档
//对于ActivityCompat,请请求权限以获取更多详细信息。
返回;
}
Location Location=locationManager.getLastKnownLocation(提供者);
如果(位置!=null){
onLocationChanged(位置);
}
locationManager.RequestLocationUpdate(提供程序,此);
//设置“查找”按钮的单击事件列表器
btnFind.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
int selectedPosition=mSprPlaceType.getSelectedItemPosition();
字符串类型=mPlaceType[selectedPosition];
StringBuilder sb=新的StringBuilder(“https://maps.googleapis.com/maps/api/place/nearbysearch/json?");
sb.追加(“位置=”+mLatitude+,“+mllongitude”);
sb.追加(“&radius=5000”);
sb.追加(“&types=“+type”);
sb.追加(“&sensor=true”);
sb.append(“&key=YOUR_-API_-key”);
//创建新的非ui线程任务以下载Google place json数据
PlacesTask PlacesTask=新的PlacesTask();
//调用类PlaceTask的“doInBackground()”方法
执行(sb.toString());
}
});
}
//注意:这是自动生成的,用于实现应用程序索引API。
//看https://g.co/AppIndexing/AndroidStudio 了解更多信息。
client=new GoogleApiClient.Builder(this.addApi(AppIndex.API).build();
}
私有字符串下载URL(字符串strUrl)引发IOException{
字符串数据=”;
InputStream iStream=null;
HttpURLConnection-urlConnection=null;
试一试{
URL=新URL(strUrl);
//创建http连接以与url通信
urlConnection=(HttpURLConnection)url.openConnection();
//连接到url
urlConnection.connect();
//从url读取数据
iStream=urlConnection.getInputStream();
BufferedReader br=新的BufferedReader(新的InputStreamReader(iStream));
StringBuffer sb=新的StringBuffer();
字符串行=”;
而((line=br.readLine())!=null){
某人附加(行);
}