简体   繁体   English

在移动设备上反应Google街景

[英]react-google-maps street view on mobile

I implemented react-google-maps package in my application. 我在应用程序中实现了react-google-maps包。 Everything works fine but when I look website on mobile and go to street view there is some option turned on by default which enables that map turns around as mobile turns around. 一切正常,但是当我在移动设备上浏览网站并转到街景时,默认情况下启用了某些选项,该选项可使地图随着移动设备而旋转。 This option is turned on by default. 默认情况下,此选项是打开的。 There is a little mobile icon in the right corner and If I press it, this will be turned off and the only way to move in street view will be with fingers. 右上角有一个小的移动图标,如果我按它,它将被关闭,而在街景视图中移动的唯一方法是用手指。 How do I make this "normal" movement with fingers a default when someone enters street view? 当有人进入街景视图时,如何使用手指进行的“正常”运动为默认设置?

EDIT: Add example 编辑:添加示例

import { withScriptjs, withGoogleMap, GoogleMap, Marker, InfoWindow, } from 'react-google-maps'
import Image from 'semantic-ui-react/dist/commonjs/elements/Image/Image'

class MapInfoComponent extends Component {
  state = {
    openInfoWindow: true,
  }

  onMarkerClick = () => {
    this.setState(prevState => ({
      openInfoWindow: !prevState.openInfoWindow,
    }))
  }

  render() {
    return (
      <GoogleMap defaultZoom={10} center={{ lat: 16.4555, lng: 14.1257, }}>
        <Marker position={{ lat: 16.4555, lng: 14.1257, }} onClick={this.onMarkerClick}>
          {this.state.openInfoWindow && (
            <InfoWindow onCloseClick={this.onMarkerClick}>
              <Image src={logo} size="small" />
            </InfoWindow>
          )}
        </Marker>
      </GoogleMap>
    )
  }
}


const GoogleMapComponent = withGoogleMap(MapInfoComponent)
const MapComponent = withScriptjs(GoogleMapComponent)

const Maps = () => (
  <div styleName="container">
    <MapComponent
      googleMapURL={`https://maps.googleapis.com/maps/api/js?key=${process.env.GOOGLE_MAPS ||
        'addGoogleMapsKey'}&v=3.exp&libraries=geometry,drawing,places`}
      loadingElement={<div style={{ height: '100%', }} />}
      containerElement={<div style={{ height: '100%', }} />}
      mapElement={<div style={{ height: '100%', }} />}
    />
  </div>
)

export default Maps

The feature you're looking for is called motionTracking . 您要查找的功能称为motionTracking

With react-google-maps , I assume you're using the StreetViewPanorama component in your code. 对于react-google-maps ,我假设您正在代码中使用StreetViewPanorama组件。 There's two props on it: defaultMotionTracking and motionTracking . 有两个道具: defaultMotionTrackingmotionTracking Set defaultMotionTracking to false. defaultMotionTracking设置为false。

Otherwise the default ends up: 否则默认值将终止:

Whether motion tracking is on or off. 运动跟踪是打开还是关闭。 Enabled by default when the motion tracking control is present , so that the POV (point of view) follows the orientation of the device. 存在运动跟踪控件时,默认情况下处于启用状态 ,以便POV(视点)遵循设备的方向。 This is primarily applicable to mobile devices. 这主要适用于移动设备。 If motionTracking is set to false while motionTrackingControl is enabled, the motion tracking control appears but tracking is off. 如果在启用motionTrackingControl时将motionTracking设置为false,则将显示运动跟踪控件,但跟踪已关闭。 The user can tap the motion tracking control to toggle this option. 用户可以点击运动跟踪控件来切换此选项。

See react-google-maps docs & Google Maps Platform docs . 请参阅react-google-maps文档Google Maps Platform文档

EDIT: Per your example, here's a possible solution (haven't tested, but conceptually should work): 编辑:根据您的示例,这是一个可能的解决方案(未经测试,但从概念上讲应该可以使用):

 import { withScriptjs, withGoogleMap, GoogleMap, Marker, InfoWindow, } from 'react-google-maps' import Image from 'semantic-ui-react/dist/commonjs/elements/Image/Image' class MapInfoComponent extends Component { state = { openInfoWindow: true, } onMarkerClick = () => { this.setState(prevState => ({ openInfoWindow: !prevState.openInfoWindow, })) } buildGoogleMap() { return ( <GoogleMap defaultZoom={10} center={{ lat: 16.4555, lng: 14.1257, }}> <Marker position={{ lat: 16.4555, lng: 14.1257, }} onClick={this.onMarkerClick}> {this.state.openInfoWindow && ( <InfoWindow onCloseClick={this.onMarkerClick}> <Image src={logo} size="small" /> </InfoWindow> )} </Marker> </GoogleMap> ) } render() { const googleMap = this.buildGoogleMap(); googleMap.getStreetView().setMotionTracking(false); return googleMap; } } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM