当尝试在Google地图上显示当前位置时,应用程序显示白色,然后崩溃。底部行的错误表示“呼叫需要许可,可能被用户拒绝”。我正在使用Android 7.0设备。在添加最后一行之前,所有工作都有效。
这是我的MapsActivity.java:
app.route(window.location.origin + '/sms/outgoing',(req,res)=>{
let data = JSON.parse(req.body)
console.log(data) //get {"to":"12345","from":"54321","body":"message"}
})
这是我的清单:
package com.example.thomas.demomaps;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class MapsActivity extends FragmentActivity implements
OnMapReadyCallback {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready
to be used.
SupportMapFragment mapFragment = (SupportMapFragment)
getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Bristol, UK.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Bristol for Bristol City FC and move the camera
LatLng Bristol = new LatLng(51.439922, -2.620950);
mMap.addMarker(new MarkerOptions().position(Bristol).title("Bristol City
FC, Ashton Gate Stadium"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(Bristol));
mMap.setMyLocationEnabled(true);
}
}
谢谢!
答案 0 :(得分:1)
由于android 6(API级别23),ACCESS_FINE_LOCATION是运行时权限,您需要请求运行时权限,请检查android文档,了解如何执行此操作https://developer.android.com/training/permissions/requesting.html