安卓IOS开发框架的选择与应用——如何提升移动应用开发效率
959
2022-10-28
OPFMaps将不同的android地图集成到他们的应用程序中
OPFMaps
OPFMaps is an open source library which provides an easy way for developers to integrate different android maps into their apps.
Currently OPFMaps supports the following maps: Google Maps, Amazon Maps, Osmdroid, Yandex Maps JavaScript API.
##How To Use
Add dependencies
The main dependencies are the opfmaps module and the OPFUtils library:
compile 'org.onepf:opfmaps:0.1.1@aar'compile 'org.onepf:opfutils:0.1.26'
Then you have to add at least one map provider dependency.
Google Maps Provider:
compile 'org.onepf:opfmaps-google:0.1.1@aar'compile 'com.google.android.gms:play-services-maps:8.1.0'
NOTE: Also for Google Maps you must add Maps API Key to the AndroidManifest.xml file.
Amazon Maps Provider:
compile 'org.onepf:opfmaps-amazon:0.1.1@aar'compile 'com.amazon:amazon-maps-api:2.0'
Osmdroid Provider:
compile 'org.onepf:opfmaps-osmdroid:0.1.1@aar'compile 'org.osmdroid:osmdroid-android:4.3'compile 'org.osmdroid:bonuspack:5.3'compile 'org.slf4j:slf4j-android:1.7.12'compile 'org.apache.commons:commons-lang3:3.4'compile 'com.google.code.gson:gson:2.3.1'
If you use Amazon Maps or/and Osmdroid you have to add the following repo which hosts amazon-maps-api and osmdroid-bounspack jars:
allprojects { repositories { ... // third-party dependencies maven { url 'https://raw.githubusercontent.com/onepf/OPF-mvn-repo/master/' } }}
Yandex Maps Provider:
compile 'org.onepf:opfmaps-yandex-web:0.1.1@aar'
Initialization
You must init OPFMapsHelper before using OPFMaps. You must do it in the Main Thread. Application.onCreate() method is the best place for this.
public class MyApplication extends Application { @Override public void onCreate() { super.onCreate(); OPFLog.setEnabled(BuildConfig.DEBUG, true); //Optional. It enables debug logs of the OPFMaps library in the debug build of your apk. final OPFMapConfiguration configuration = new OPFMapConfiguration.Builder() .addProviders(new YaWebMapProvider(), new OsmdroidMapProvider(), new GoogleMapProvider(), new AmazonMapProvider()) //Add all providers. The priority of the providers corresponds to the order in which they were added. .setSelectSystemPreferred(true) //If you set true, the system push provider will get the highest priority. Default value is false. .build(); OPFMapHelper.getInstance().init(this, configuration); }}
Using
Add the main.xml file which contains a
Get OPFMap object in your activity:
public class MainActivity extends Activity implements OnMapReadyCallback { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final OPFMapFragment mapFragment = (OPFMapFragment) getFragmentManager().findFragmentById(R.id.map); mapFragment.getMapAsync(this); } @Override public void onMapReady(@NonNull final OPFMap opfMap) { opfMap.addMarker(new OPFMarkerOptions() .position(new OPFLatLng(0, 0)) .title("Marker")); }}
You can use OPFMapFragment/OPFSupportMapFragment or OPFMapView to obtain the instance of OPFMap class (The main Maps API class).
##More Information
The OPFMaps library delegates all methods invokes to the specific map provider which is selected during initialization. It has almost the same API as Google Maps Android API v2. So for more information see Google instructions.
##Restrictions
The OPFMaps library provides all methods which are provided by Google Maps. Not all map providers support whole API. For example Yandex Web Provider doesn't support rotation and tilt gestures and Amazon Map Provider doesn't support draggable markers. See Javadoc of each OPFMapProvider before using to know which methods are stubbed by the specific provider.
License
Copyright 2012-2015 One Platform FoundationLicensed under the Apache License, Version 2.0 (the "License");you may not use this file except in compliance with the License.You may obtain a copy of the License at http://apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。