-
Notifications
You must be signed in to change notification settings - Fork 14
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
Mapkit won't center? #65
Comments
Just to be clear; sometimes the marker isn't even inside of the visible map range when I update |
Hi @khorwood-openai, Thank you for your interest in mapkit-react! The strange behavior you are facing seems to come from MapKit JS itself. The What I would suggest doing instead is to use MapKit JS’s imperative API (which is available when using mapkit-react through import React, { useRef, useState } from 'react';
import { Map, Marker } from 'mapkit-react';
const token = "…";
export const MapWithMovingMarker = () => {
const locations = [
{ name: 'Jet d’eau', latitude: 46.20738751546706, longitude: 6.155891756231 },
{ name: 'Horloge fleurie', latitude: 46.20418989653241, longitude: 6.150997214058191 },
{ name: 'Bains des Pâquis', latitude: 46.21042332922134, longitude: 6.154311850592231 },
];
const [selectedLocationIndex, setSelectedLocationIndex] = useState(0);
const selectedLocation = locations[selectedLocationIndex];
const mapRef = useRef<mapkit.Map | null>(null);
return (
<div style={{ display: 'flex', flexDirection: 'column', height: '100%' }}>
<div style={{ flex: 1 }}>
<Map
initialRegion={{
centerLatitude: selectedLocation.latitude,
centerLongitude: selectedLocation.longitude,
latitudeDelta: 0.005,
longitudeDelta: 0.005,
}}
token={token}
ref={mapRef}
>
<Marker
latitude={selectedLocation.latitude}
longitude={selectedLocation.longitude}
title={selectedLocation.name}
/>
</Map>
</div>
<div style={{ padding: '1rem' }}>
<select
value={selectedLocationIndex}
onChange={(e) => {
const newIndex = Number(e.target.value);
setSelectedLocationIndex(newIndex);
mapRef.current?.setCenterAnimated(new mapkit.Coordinate(
locations[newIndex].latitude,
locations[newIndex].longitude,
));
}}
>
{locations.map((location, index) => (
<option key={location.name} value={index}>{location.name}</option>
))}
</select>
</div>
</div>
);
}; Screenshot.2024-09-08.at.12.03.36.mov |
How can you center and zoom in? |
@passatgt You can use |
Thanks, thats what i figured. Its a bit difficoult to use setRegionAnimated, because you don't actually set zoom level, but the visible area diameter. And doing setCenterAnimated with setCameraDistanceAnimated doesn't seem to work if you run them both at the same time. Kinda weird we don't have a simple zoom levels like Google Maps from 0 to 22 or something like that. |
yeah... I am having a hard time adjusting to the map too. Also I don't know if it is just me but the document from Apple seems really hard to read and know what the hack I have to do with. I don't see any example or anything like that to have a clue. Like glyphImage. It says 'Object' but what object haha |
This is my project, looks and kinda works nice: https://points.kvikk.hu |
Heya! In order to do this, do I have to add <script src="https://cdn.apple-mapkit.com/mk/5.x.x/mapkit.core.js" crossorigin async data-callback="initMapKit" data-libraries="services,full-map,geojson"></script>
|
Hey @parttiez, thank you for your interest in mapkit-react! You don’t need to add Don’t forget to include a correct value for |
Hey all, I'm evaluating using this project for a small demo.
I'm using this code, where
marker
andcoords
are identical objects.The Map is part of a flexbox component that looks roughly like;
Whenever I update coordinates with
cameraBoundary
, the map always centers on the bottom left of the boundary area.Something I noticed when inspecting the HTML;
You'll notice the
canvas
width and height values are double thestyle
values. Mywindow.devicePixelRatio
setting is set to2
, and I think this may be related to the cause.Any chance y'all can fix this? I'm happy to just use the default MapKit library but this seemed like a neat and simple solution.
The text was updated successfully, but these errors were encountered: