@heycar/heycars-map 0.3.3 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hooks/useMapAutoComplete.d.ts +3 -0
- package/dist/hooks-business/useBusinessMapAutoComplete.d.ts +1 -0
- package/dist/index.cjs +52 -52
- package/dist/index.js +975 -969
- package/dist/types/interface.d.ts +1 -0
- package/package.json +1 -1
- package/src/Demo/DemoBusinessRecomendPlace.tsx +1 -1
- package/src/hooks/useMapAutoComplete.ts +27 -12
- package/src/types/interface.ts +1 -0
package/package.json
CHANGED
|
@@ -18,7 +18,7 @@ const SomeAutoComplete = defineSetup(function SomeAutoComplete(props: { cityName
|
|
|
18
18
|
return () => {
|
|
19
19
|
const list = autoCompletePlaces.value.map((place) => (
|
|
20
20
|
<div>
|
|
21
|
-
{place.lng} | {place.lat} | {place.name} | {place.description}
|
|
21
|
+
{place.lng} | {place.lat} | {place.name} | {place.description} | {place.distance}
|
|
22
22
|
</div>
|
|
23
23
|
));
|
|
24
24
|
return (
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { ref, watch } from "vue-demi";
|
|
2
2
|
import type { AutoCompletePlace, Region } from "../types/interface";
|
|
3
|
+
import { useGeoLocation } from "./useGeoLocation";
|
|
4
|
+
import { useMapGeometry } from "./useMapGeometry";
|
|
3
5
|
import { MapLogProps, useMapLogVariable } from "./useMapLog";
|
|
4
6
|
import { useMapSupplier } from "./useMapSupplier";
|
|
5
7
|
import { useUpdate } from "./useUdate";
|
|
@@ -13,6 +15,8 @@ export const useAmapAutoComplete = (props: UseMapAutoCompleteProps) => {
|
|
|
13
15
|
const cityRef = ref(city);
|
|
14
16
|
useMapLogVariable(props, "useAmapAutoComplete", cityRef, "cityRef");
|
|
15
17
|
const { readyPromise } = useMapSupplier();
|
|
18
|
+
const { apiMapDistance } = useMapGeometry();
|
|
19
|
+
const { geoPosition } = useGeoLocation();
|
|
16
20
|
const keywordRef = ref("");
|
|
17
21
|
const autoCompletePlacesRef = ref<AutoCompletePlace[]>([]);
|
|
18
22
|
const { update, idx: updateKey } = useUpdate();
|
|
@@ -31,15 +35,20 @@ export const useAmapAutoComplete = (props: UseMapAutoCompleteProps) => {
|
|
|
31
35
|
await readyPromise;
|
|
32
36
|
const amapPlaceSearch = new AMap.PlaceSearch({ city: cityRef.value.name });
|
|
33
37
|
amapPlaceSearch.search(keywordRef.value, (status, result) => {
|
|
38
|
+
const from = geoPosition.value;
|
|
34
39
|
switch (status) {
|
|
35
40
|
case "complete": {
|
|
36
41
|
autoCompletePlacesRef.value = (result as AMap.PlaceSearchResult).poiList.pois.map(
|
|
37
|
-
(poi) =>
|
|
38
|
-
lat
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
(poi) => {
|
|
43
|
+
const { lat, lng } = poi.location;
|
|
44
|
+
return {
|
|
45
|
+
lat,
|
|
46
|
+
lng,
|
|
47
|
+
name: poi.name,
|
|
48
|
+
description: poi.address,
|
|
49
|
+
distance: from ? apiMapDistance(from, [lng, lat]) : undefined,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
43
52
|
);
|
|
44
53
|
return;
|
|
45
54
|
}
|
|
@@ -62,6 +71,8 @@ export const useGmapAutoComplete = (props: UseMapAutoCompleteProps) => {
|
|
|
62
71
|
const { city } = props;
|
|
63
72
|
const cityRef = ref({ ...city });
|
|
64
73
|
const { readyPromise } = useMapSupplier();
|
|
74
|
+
const { apiMapDistance } = useMapGeometry();
|
|
75
|
+
const { geoPosition } = useGeoLocation();
|
|
65
76
|
const keywordRef = ref("");
|
|
66
77
|
const autoCompletePlacesRef = ref<AutoCompletePlace[]>([]);
|
|
67
78
|
const { update, idx: updateKey } = useUpdate();
|
|
@@ -86,16 +97,20 @@ export const useGmapAutoComplete = (props: UseMapAutoCompleteProps) => {
|
|
|
86
97
|
bounds: cityRef.value.bound,
|
|
87
98
|
},
|
|
88
99
|
(result, status) => {
|
|
100
|
+
const from = geoPosition.value;
|
|
89
101
|
switch (status) {
|
|
90
102
|
case google.maps.places.PlacesServiceStatus.OK:
|
|
91
|
-
autoCompletePlacesRef.value = result!.map(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
103
|
+
autoCompletePlacesRef.value = result!.map(({ geometry, name, formatted_address }) => {
|
|
104
|
+
const lng = geometry?.location?.lng() ?? 0;
|
|
105
|
+
const lat = geometry?.location?.lat() ?? 0;
|
|
106
|
+
return {
|
|
107
|
+
lng,
|
|
108
|
+
lat,
|
|
95
109
|
name: name ?? "",
|
|
96
110
|
description: formatted_address ?? "",
|
|
97
|
-
|
|
98
|
-
|
|
111
|
+
distance: from ? apiMapDistance(from, [lng, lat]) : undefined,
|
|
112
|
+
};
|
|
113
|
+
});
|
|
99
114
|
return;
|
|
100
115
|
case google.maps.places.PlacesServiceStatus.ZERO_RESULTS:
|
|
101
116
|
case google.maps.places.PlacesServiceStatus.NOT_FOUND:
|