使用Windows API密钥时,不会显示google maps infowindow.content

时间:2016-04-28 17:01:48

标签: google-maps google-maps-api-3

我有一个问题,如果我使用谷歌地图api客户端密钥,我的代码将正常工作,但不是当我使用谷歌地图API密钥时(我们需要两者)。在任何一种情况下,地图都会正确显示,我们也不会从谷歌地图服务器中获得任何错误,这意味着服务器也接受了API密钥。但是,当提供地图API密钥时,实际的infowindow内容将不会显示(使用类型为client的密钥,它可以正常工作)。我确认两种情况下的内容(在msg var中提供)完全相同。文档中没有任何内容表明存在任何具体差异。欢迎任何想法/建议。

public class MainActivity extends AppCompatActivity implements SensorEventListener {
    private float[] gravity = new float[3];
    private float[] linear_acceleration = new float[3];

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        SensorManager mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
        Sensor mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
        mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_NORMAL);
    }

    @Override
    public void onSensorChanged(SensorEvent event) {
        // alpha is calculated as t / (t + dT)
        // with t, the low-pass filter's time-constant
        // and dT, the event delivery rate

        final float alpha = 0.8f;

        gravity[0] = alpha * gravity[0] + (1 - alpha) * event.values[0];
        gravity[1] = alpha * gravity[1] + (1 - alpha) * event.values[1];
        gravity[2] = alpha * gravity[2] + (1 - alpha) * event.values[2];

        linear_acceleration[0] = event.values[0] - gravity[0];
        linear_acceleration[1] = event.values[1] - gravity[1];
        linear_acceleration[2] = event.values[2] - gravity[2];

        float scalarProduct = gravity[0] * linear_acceleration[0] +
                gravity[1] * linear_acceleration[1] +
                gravity[2] * linear_acceleration[2];
        float gravityVectorLength = (float) Math.sqrt(gravity[0] * gravity[0] +
                gravity[1] * gravity[1] + gravity[2] * gravity[2]);
        float lianearAccVectorLength = (float) Math.sqrt(linear_acceleration[0] * linear_acceleration[0] +
                linear_acceleration[1] * linear_acceleration[1] + linear_acceleration[2] * linear_acceleration[2]);

        float cosVectorAngle = scalarProduct / (gravityVectorLength * lianearAccVectorLength);

        TextView tv = (TextView) findViewById(R.id.tv);
        if (lianearAccVectorLength > 2) {//increase to detect only bigger accelerations, decrease to make detection more sensitive but noisy
            if (cosVectorAngle > 0.5) {
                tv.setText("Down");
            } else if (cosVectorAngle < -0.5) {
                tv.setText("Up");
            }
        }
    }

    @Override
    public void onAccuracyChanged(Sensor sensor, int i) {

    }
}

1 个答案:

答案 0 :(得分:0)

碰巧,代码有一些不再支持的语法(谷歌支持提供了这些信息)。我通过替换下面的行修复了这个问题 infowindow.content = msg; 同 infowindow.setContent(MSG);