This is the second day of my participation in the November Gwen Challenge. Check out the details: the last Gwen Challenge 2021

preface

This article was published after the personal Information Protection Law was promulgated and the App’s AUtonavi SDK was reformed.

Mainly deal with their App business Bug, we just have a look

Just as I breathed a sigh of relief after the AMap SDK rectification, packaged to the test, not for a while, the test feedback came back:

You will be surprised when you open the App!! The map style is not the same as before!!

Amap SDK before rectification Amap SDK after rectification

I was wondering when I saw it, I upgraded a Gaode map SDK, how even the map style also changed?

Analysis of the Bug

Because I took over this project halfway and was not familiar with some businesses, I first confirmed the following things with my colleagues in requirements, testing and Android:

  • Is the map style of our App dark?

    Answer to demand: Yes, it has always been similar to the style of App, which is dark color.

  • Is online App good?

    Test reply: Online App map style is good, this Bug only exists with the upgrade of AmAP, I even went to download the test version of AMAP SDK without upgrade, found no problem.

  • Android App upgrade amap after the same problem?

    Android colleague: No abnormality has been found so far.

Through the above inquiry, I basically confirmed that the SDK upgrade of Amap led to the emergence of this Bug.

Location problem

So I immediately went to the code to look at the code involved in customizing amap, and soon found:

NSString *path = [NSString stringWithFormat:@"%@/style.data", [NSBundle mainBundle].bundlePath]; NSData *data = [NSData dataWithContentsOfFile:path]; NSString *extraPath = [NSString stringWithFormat:@"%@/style_extra.data", [NSBundle mainBundle].bundlePath]; NSData *extraData = [NSData dataWithContentsOfFile:extraPath]; MAMapCustomStyleOptions *options = [[MAMapCustomStyleOptions alloc] init]; options.styleData = data; options.styleExtraData = extraData; [self.myMapView setCustomMapStyleOptions:options]; [self.myMapView setCustomMapStyleEnabled:YES];Copy the code

Style. data and style_extra.data are read locally as configuration items and then used in the map.

I immediately had two tests:

  • Are these two files still in the project?

    In the project.

  • What is the change history of these two files in Git?

    There has been no change in the last year. There should be no change to these two files in this upgrade, nor any artificial change.

In this case, I would like to go to the Amap SDK documentation to look up the setCustomMapStyleOptions API

I don’t know. I’m scared.

In general, the cause of the abnormal map style was found:

Amap SDK upgrade span is too large, the previous AMap SDK version is very old, this time directly upgraded to 8.1.0, the oldstyle.dataandstyle_extra.dataIt is no longer available in the new SDK.

To solve the problem

Once the problem is identified, it’s easy to solve:

  • Go to the website and select the map style:

  • Download the new style file:

  • Delete the previous one in the projectstyle.dataandstyle_extra.dataFile, using the style file downloaded this time.

Problem solved!!

Reference documentation

Autonavi custom map styles

iOS_Map_Doc/AMap_iOS_API_Doc_3D

conclusion

This is a Bug caused by the SDK upgrade of Gaode Map, which can only be regarded as a little experience. Here is just a record of the back and forth of their investigation.