vitalidze / traccar-web

Traccar Web UI mod
http://traccar.litvak.su/
151 stars 145 forks source link

Where to change the google map api key? #754

Open onethings opened 8 years ago

onethings commented 8 years ago

Hi, I went to change open lay map(google map) with my google map api, Where to change the code? I can't find https://github.com/tananaev/traccar/blob/master/src/org/traccar/geocode/GoogleReverseGeocoder.java to edit it.

Thanks.

vitalidze commented 8 years ago

This is the code of the backend project and it is actually related to the reverse geocoding. Here is where maps are initialized in this project: https://github.com/vitalidze/traccar-web/blob/dev/src/main/java/org/traccar/web/client/view/MapView.java#L131

onethings commented 8 years ago

Thank you, and which place i can add the api code. case GOOGLE_HYBRID: GoogleV3Options gHybridOptions = new GoogleV3Options(); gHybridOptions.setNumZoomLevels(20); gHybridOptions.setType(GoogleV3MapType.G_HYBRID_MAP); return new GoogleV3(mapType.getName(), gHybridOptions); case GOOGLE_NORMAL: GoogleV3Options gNormalOptions = new GoogleV3Options(); gNormalOptions.setNumZoomLevels(22); gNormalOptions.setType(GoogleV3MapType.G_NORMAL_MAP); return new GoogleV3(mapType.getName(), gNormalOptions); case GOOGLE_SATELLITE: GoogleV3Options gSatelliteOptions = new GoogleV3Options(); gSatelliteOptions.setNumZoomLevels(20); gSatelliteOptions.setType(GoogleV3MapType.G_SATELLITE_MAP); return new GoogleV3(mapType.getName(), gSatelliteOptions); case GOOGLE_TERRAIN: GoogleV3Options gTerrainOptions = new GoogleV3Options(); gTerrainOptions.setNumZoomLevels(16); gTerrainOptions.setType(GoogleV3MapType.G_TERRAIN_MAP); return new GoogleV3(mapType.getName(), gTerrainOptions);

vitalidze commented 8 years ago

Unfortunately I don't see a way to set up the API key for google maps. I need to make some further investigation, maybe it will be possible through JSNI, by calling some javascript code directly.

onethings commented 8 years ago

Is possible replace https://github.com/vitalidze/traccar-web/blob/dev/src/main/webapp/traccar.html#L25 with to make it work? Cause without api key , when select google map, it's display " Oops! Something went wrong. This page didn't load Google Maps correctly. See the JavaScript console for technical details."

vitalidze commented 8 years ago

Yes, according to the docs https://developers.google.com/maps/documentation/javascript/get-api-key?hl=en#premium-key this is the correct place to insert your API key. You can change it inside the traccar-web.war file, which is actually a zip archive.

onethings commented 8 years ago

ok, Thank you very much.

Gfernandezh commented 8 years ago

Hello vitalidze , onethings I wolud like to ask you if you resolve the problem because I have the same problem

Oops! Something went wrong. This page didn't load Google Maps correctly. See the JavaScript console for technical details.

I wish you help me

regards

onethings commented 8 years ago

@Gfernandez Register google map Api key for your domain name or ip that you use for traccar. Then edit and place api key in https://github.com/vitalidze/traccar-web/blob/dev/src/main/webapp/traccar.html#L25 . Rebuild traccar-web.war file and replace in /opt/traccar/

shubhamalive commented 8 years ago

@onethings Do we have to edit this line or add new line, as i tried adding < script async defer src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap" type="text/javascript >< / script > below the above code, but it didnt work. Can you tell me the correct way of doiung it.

onethings commented 8 years ago

@shubhamalive you need to replace YOUR_API_KEY with your own google map api key in above URL. You can registrat your own google map api key at https://developers.google.com/maps/documentation/javascript/get-api-key?hl=en

shubhamalive commented 8 years ago

screenshot_5 @onethings i have registered and got my API, but how to use it, can you give me a sample URL

I have done it like this,

onethings commented 8 years ago

Rebuild traccar-web.war file and replace in /opt/traccar/

http://traccar.litvak.su/building.html

shubhamalive commented 8 years ago

@onethings Thanks Mate. That worked :100: % :+1:

mataier commented 8 years ago

1.downloaded traccar-web.git, - 2.Change to the cloned repo folder????? - cd traccar-web. ?????? then I can't move

vitalidze commented 8 years ago

@mataier you can just unpack the traccar-web.war, update traccar.html and then pack it back. The traccar-web.war is an ordinary zip-archive.

mataier commented 8 years ago

insert the key court (?)

mataier commented 8 years ago
mataier commented 8 years ago

this

<script src="js/openlayers/OpenStreetMap.js"></script>
<script src="//maps.google.com/maps/api/js(?)v=3"></script>
<script type="text/javascript" src="js/openseamap/harbours.js"></script>
<script type="text/javascript" src="js/openseamap/map_utils.js"></script>
<script type="text/javascript" src="js/stamen/tile.stamen.js"></script>
<script type="text/javascript" src="traccar/traccar.nocache.js"></script>
mataier commented 8 years ago

yes, thanks, that worked!!!!

mataier commented 8 years ago

how to add a map ArcGis?

vitalidze commented 8 years ago

@mataier first of all, please don't post such questions in this thread. It's not related with adding map providers.

To add a map you need to update code and rebuild project. See this commit for example of such changes: https://github.com/vitalidze/traccar-web/commit/f2642016545d4ae084b36ecb43e2cad7c0941234 Also this ticket may be of help: #699

sdip025 commented 7 years ago

Hii, When I used version 2.12,there was traccar-web.war file and traccar.html file .But in version 3.7 there is no war file.How and where i will set api key?

vitalidze commented 7 years ago

@sdip025 There must be a traccar-web.war file if you followed installation instructions: http://traccar.litvak.su/installation.html

Otherwise you are using a standard web UI of traccar and all questions about it should go here: https://github.com/tananaev/traccar-web/issues

tsdantas01 commented 5 years ago

@shubhamalive you need to replace YOUR_API_KEY with your own google map api key in above URL. You can registrat your own google map api key at https://developers.google.com/maps/documentation/javascript/get-api-key?hl=en

hello, I tried the

Rebuild traccar-web.war file and replace in /opt/traccar/

http://traccar.litvak.su/building.html

Hello, I tried this recommendation, but it doesn`t Worked,