Copyright ? 2014 Microsoft Mobile Oy. All rights reserved.
Microsoft is a registered trademark of Microsoft Corporation. Nokia and HERE are
trademarks and/or registered trademarks of Nokia Corporati...
If you think the Android project capture-the-flag listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Copyright (c) 2014 Microsoft Mobile. All rights reserved.
* See the license text file provided with this project for more information.
*///fromwww.java2s.compackage com.nokia.example.capturetheflag.map.google;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.util.DisplayMetrics;
import com.google.android.gms.maps.model.BitmapDescriptor;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.nokia.example.capturetheflag.map.MarkerFactoryBase;
import com.nokia.example.capturetheflag.network.model.Flag;
import com.nokia.example.capturetheflag.network.model.Player;
/**
* Helper class using Google APIs for creating map markers, e.g. player or flag marker.
*/publicclass MarkerFactoryGoogle extends MarkerFactoryBase {
privatestaticfinalfloat ANCHOR_U = 1.0f - (12.0f / (float) PLAYER_NAME_SIZE);
privatestaticfinalfloat ANCHOR_V = 1.0f;
/**
* Creates and returns a {@link MarkerOptions} instance for a player marker
* to be used for creating a new marker on the Google map.
*
* @param player Player data, @see {@link Player}.
* @param metrics Display metrics to use for size calculations.
* @param res Resources to use.
* @return Map marker options for the player marker, @see {@link MarkerOptions}.
*/publicstatic MarkerOptions createPlayerMarker(final Player player, DisplayMetrics metrics, Resources res) {
Bitmap bitmap = getBitmapForPlayer(player, metrics, res);
BitmapDescriptor bmap = BitmapDescriptorFactory.fromBitmap(bitmap);
MarkerOptions marker = new MarkerOptions().position(new LatLng(player.getLatitude(), player.getLongitude())).icon(bmap).anchor(ANCHOR_U, ANCHOR_V);
return marker;
}
/**
* Creates and returns a {@link MarkerOptions} instance for a flag marker
* to be used for creating a new marker on the Google map.
*
* @param player Player data, @see {@link Player}.
* @param metrics Display metrics to use for size calculations.
* @param res Resources to use.
* @return Map marker options for the player marker, @see {@link MarkerOptions}.
*/publicstatic MarkerOptions createFlagMarker(Flag flag, Bitmap bitmap, int size) {
BitmapDescriptor bmap = BitmapDescriptorFactory.fromBitmap(Bitmap.createScaledBitmap(bitmap, size, size, true));
MarkerOptions marker = new MarkerOptions().position(new LatLng(flag.getLatitude(), flag.getLongitude())).icon(bmap);
return marker;
}
}