Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create examples of custom myLocationButton and zoomButtons #1874

Closed
alvelig opened this issue Dec 13, 2017 · 9 comments
Closed

Create examples of custom myLocationButton and zoomButtons #1874

alvelig opened this issue Dec 13, 2017 · 9 comments
Assignees
Labels

Comments

@alvelig
Copy link
Contributor

alvelig commented Dec 13, 2017

No description provided.

@ozluy
Copy link

ozluy commented Jul 20, 2018

Any work for that????

@samReact
Copy link

Some problem for me, I want to know how to change position of my current location button...

@andresmafra
Copy link

Is this available?

@gyurka00
Copy link

Any update?

@HughBerriez
Copy link

HughBerriez commented Jan 18, 2019

Custom myLocationButton example:

Here's the component I made in case you'd like to create your own. I tried getting the packages location button to work for my project on Android and nearly became bald because of it (All those solutions with re-rendering the Map component upon mapDidLoad or whatever definitely didn't work for me) so here's a snippet of my own code (no need to worry about my !isListingSelected statement etc). The use of refs here is the trick - you steal snippets from the baked in methods of the MapListing component with the refs - and then call the method you'd like when your custom component is tapped.

this.state = {
      latitude: INITIAL_REGION.latitude,
      longitude: INITIAL_REGION.longitude,
      error: null,
      isListingSelected: false
    }
/**
   * Sets the overall lat long of the map viewport and thus the animation engages
   */
  getCurrentPosition = () => {
    navigator.geolocation.getCurrentPosition(
      position => {
        this.setState({
          latitude: position.coords.latitude,
          longitude: position.coords.longitude,
          error: null
        })
        _mapView.animateToCoordinate(
          {
            latitude: this.state.latitude,
            longitude: this.state.longitude
          },
          1000
        )
      },
      error => {
        console.log(error)
        this.setState({ error: error.message })
      }
    )
  }
/**
   * Show find my location button
   * TODO: needs to have SDK26 permissions added to it in the near future
   */
  renderShowLocationButton = () => {
    if (!this.state.isListingSelected) {
      return (
        <TouchableOpacity
          style={styles.myLocationButton}
          onPress={() => {
            this.getCurrentPosition()
          }}
        >
          <MaterialCommunityIcons name='crosshairs-gps' size={24} />
        </TouchableOpacity>
      )
    }
    return
    // Should add error handling if needed too
  }
//In your map component
render() {
    ...
    <MapView
    ref={mapView => {
            _mapView = mapView
          }}
    {this.renderShowLocationButton()}
    ...
    />
}
const styles = StyleSheet.create({
  map: {
    ...StyleSheet.absoluteFillObject
  },
  myLocationButton: {
    backgroundColor: colors.surface,
    position: 'absolute',
    bottom: 10,
    right: 10,
    padding: 15,
    elevation: 3,
    alignItems: 'center',
    alignSelf: 'flex-end',
    justifyContent: 'center',
    borderRadius: 50
  }
})

@Anytram
Copy link

Anytram commented Aug 2, 2019

Could someone help with zoom in/out buttons? I can't make it work properly... And there is no valid and working examples in Internet... (Typescript, React 0.60)

@stale
Copy link

stale bot commented Oct 3, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Oct 3, 2020
@stale stale bot closed this as completed Oct 10, 2020
@Louisten
Copy link

any update?

@john73-cloud
Copy link

is there any update concerning the show my location button location

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants