Rectangle 27 12

I had the same problem when I try to build a simple app, following the Android MapView tutorial.

The app showed this exception in AVD for the file file main.xml:

Failed to find style 'mapViewStyle' in current theme

At last I found that there is a mistake in file AndroidManifest.xml:

<uses-library android:name="com.google.android.maps" />
<application>
<manifest>

Sorry this is not the solution in my case.

this is not a fix, I have it as child of the application element.

java - Android Google Maps Failed to find style 'mapViewStyle' in curr...

java android google-maps
Rectangle 27 12

I had the same problem when I try to build a simple app, following the Android MapView tutorial.

The app showed this exception in AVD for the file file main.xml:

Failed to find style 'mapViewStyle' in current theme

At last I found that there is a mistake in file AndroidManifest.xml:

<uses-library android:name="com.google.android.maps" />
<application>
<manifest>

Sorry this is not the solution in my case.

this is not a fix, I have it as child of the application element.

java - Android Google Maps Failed to find style 'mapViewStyle' in curr...

java android google-maps
Rectangle 27 4

I tried to point this out to the moderators but I was ignored...

this one didn't help as well .. super useless list of links..

@ewoks +1 I totally agree - this was my attempt to get the moderators to combine these questions - they are all totally useless. Unfortunately when I flagged the question as duplicate, the moderator disagreed.

java - Android Google Maps Failed to find style 'mapViewStyle' in curr...

java android google-maps
Rectangle 27 4

I tried to point this out to the moderators but I was ignored...

this one didn't help as well .. super useless list of links..

@ewoks +1 I totally agree - this was my attempt to get the moderators to combine these questions - they are all totally useless. Unfortunately when I flagged the question as duplicate, the moderator disagreed.

java - Android Google Maps Failed to find style 'mapViewStyle' in curr...

java android google-maps
Rectangle 27 2

I was having the same problem, and it turned out the problem was I had targeted the app towards the Google 4.0 APIs, but in the Manifest file specified Android API 10 (2.3.3).

Once I changed the project's target from 4.0 to 2.3.3 (API 10), it worked better.

java - Android Google Maps Failed to find style 'mapViewStyle' in curr...

java android google-maps
Rectangle 27 2

I had the same issue when creating a Google Map view that worked well until I cleaned the project after placing a new icon.png in a drawable folder (Project >> Clean). Many times the cleaning process will install an import statement at the top program code, which overrides the R.java file in your project. The solution was to simply remove the following import statement:

after the project was saved and rebuilt without issue.

java - Android Google Maps Failed to find style 'mapViewStyle' in curr...

java android google-maps
Rectangle 27 2

My answer may be a late one, but i hope that it'll deals with the actual reason and sure it could be helpful for those who are going to search about the same problem in future.

This type of errors,

1. Android Google Maps Failed to find style 'mapViewStyle' in current theme
2. Failed to find style 'imageButtonStyle' in current theme 
3. Failed to find style 'editTextStyle' in current theme 
4. Failed to find style 'textViewStyle' in current theme

Anything from the above list it may be,

We have selected the unavailable Theme for the layout.

  • The selected theme is not available in themes.xml file.
  • The selected theme is belongs to higher version sdk, but our current target sdk is lower one.
  • when you copy the whole layout file and try to implement it in your project. a. Your may forgot to copy themes.xml file b. You may have lower target sdk, the original layout created with higher target sdk.

(Open and View the layout file in the Graphical Layout View, and look at the top Right corner. There your themes for the layout have been selected.)

  • So click the dropdown list for theme selection and choose the available themes according to your project themes and targeted sdk themes. (OR)
  • If the theme is a custom one , if you are required it , then copy the themes.xml file to your project from the source where you copied the layout xml file. (OR)
  • If the theme is sdk avail theme, if you are required it , then change your target according to your selected theme.

Hope,This might be helpful for somebody.

This is an exact copy of your answer stackoverflow.com/questions/8513278/. This issue is not related to the themes.xml, as the theme is inherited from the Maps API.

java - Android Google Maps Failed to find style 'mapViewStyle' in curr...

java android google-maps
Rectangle 27 2

I had the same issue when creating a Google Map view that worked well until I cleaned the project after placing a new icon.png in a drawable folder (Project >> Clean). Many times the cleaning process will install an import statement at the top program code, which overrides the R.java file in your project. The solution was to simply remove the following import statement:

after the project was saved and rebuilt without issue.

java - Android Google Maps Failed to find style 'mapViewStyle' in curr...

java android google-maps
Rectangle 27 2

My answer may be a late one, but i hope that it'll deals with the actual reason and sure it could be helpful for those who are going to search about the same problem in future.

This type of errors,

1. Android Google Maps Failed to find style 'mapViewStyle' in current theme
2. Failed to find style 'imageButtonStyle' in current theme 
3. Failed to find style 'editTextStyle' in current theme 
4. Failed to find style 'textViewStyle' in current theme

Anything from the above list it may be,

We have selected the unavailable Theme for the layout.

  • The selected theme is not available in themes.xml file.
  • The selected theme is belongs to higher version sdk, but our current target sdk is lower one.
  • when you copy the whole layout file and try to implement it in your project. a. Your may forgot to copy themes.xml file b. You may have lower target sdk, the original layout created with higher target sdk.

(Open and View the layout file in the Graphical Layout View, and look at the top Right corner. There your themes for the layout have been selected.)

  • So click the dropdown list for theme selection and choose the available themes according to your project themes and targeted sdk themes. (OR)
  • If the theme is a custom one , if you are required it , then copy the themes.xml file to your project from the source where you copied the layout xml file. (OR)
  • If the theme is sdk avail theme, if you are required it , then change your target according to your selected theme.

Hope,This might be helpful for somebody.

This is an exact copy of your answer stackoverflow.com/questions/8513278/. This issue is not related to the themes.xml, as the theme is inherited from the Maps API.

java - Android Google Maps Failed to find style 'mapViewStyle' in curr...

java android google-maps
Rectangle 27 2

I was having the same problem, and it turned out the problem was I had targeted the app towards the Google 4.0 APIs, but in the Manifest file specified Android API 10 (2.3.3).

Once I changed the project's target from 4.0 to 2.3.3 (API 10), it worked better.

java - Android Google Maps Failed to find style 'mapViewStyle' in curr...

java android google-maps
Rectangle 27 3

If it fails on myLocation.getLatitude(); as you mentioned in the comment then it means that locationManager.getLastKnownLocation(provider); doesn't return a last known location because it doesn't have one so it return null and this is the reason you have a NullPointerExeception error. you need to implement a LocationListener in this case and to run this method after you have received at least one location update.

To implement LocationListener you can check this example:

I guess that this reading material could be really handy as well for you:

It works like a charm. Thanks Dude.

java - Can't find user location Google Maps Api v2 - Stack Overflow

java android google-maps latitude-longitude google-maps-api-2
Rectangle 27 0

If it fails on myLocation.getLatitude(); as you mentioned in the comment then it means that locationManager.getLastKnownLocation(provider); doesn't return a last known location because it doesn't have one so it return null and this is the reason you have a NullPointerExeception error. you need to implement a LocationListener in this case and to run this method after you have received at least one location update.

To implement LocationListener you can check this example:

I guess that this reading material could be really handy as well for you:

It works like a charm. Thanks Dude.

java - Can't find user location Google Maps Api v2 - Stack Overflow

java android google-maps latitude-longitude google-maps-api-2
Rectangle 27 0

private Location getMyLocation() {
    // Get location from GPS if it's available
    LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    Location myLocation = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);

    // Location wasn't found, check the next most accurate place for the
    // current location
    if (myLocation == null) {
        Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_COARSE);
        // Finds a provider that matches the criteria
        String provider = lm.getBestProvider(criteria, true);
        // Use the provider to get the last known location
        myLocation = lm.getLastKnownLocation(provider);
    }
    return myLocation;
}

Location location = this.getMyLocation();               
LatLng locationGPS = new LatLng(location.getLatitude(), location.getLongitude());

java - Can't find user location Google Maps Api v2 - Stack Overflow

java android google-maps latitude-longitude google-maps-api-2
Rectangle 27 0

private Location getMyLocation() {
    // Get location from GPS if it's available
    LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    Location myLocation = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);

    // Location wasn't found, check the next most accurate place for the
    // current location
    if (myLocation == null) {
        Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_COARSE);
        // Finds a provider that matches the criteria
        String provider = lm.getBestProvider(criteria, true);
        // Use the provider to get the last known location
        myLocation = lm.getLastKnownLocation(provider);
    }
    return myLocation;
}

Location location = this.getMyLocation();               
LatLng locationGPS = new LatLng(location.getLatitude(), location.getLongitude());

java - Can't find user location Google Maps Api v2 - Stack Overflow

java android google-maps latitude-longitude google-maps-api-2
Rectangle 27 0

You can use Location to determine the distance between two addresses:

private static float distance(LatLng current, LatLng last){
    if(last==null)
        return 0;
    Location cL = new Location("");
    cL.setLatitude(current.latitude);
    cL.setLongitude(current.longitude);

    Location lL = new Location("");
    lL.setLatitude(last.latitude);
    lL.setLongitude(last.longitude);

    return lL.distanceTo(cL);
}

Thanks for the reply. After finding the distance, i stored all of them in an arrayList and then found min using Collections.min(). But now how do i keep track of LatLng which corresponds to this min distance?

java - Find the location nearest to current location from an array of ...

java android google-places-api google-maps-android-api-2
Rectangle 27 0

I had the same issue when creating a Google Map view that worked well until I cleaned the project after placing a new icon.png in a drawable folder (Project >> Clean). Many times the cleaning process will install an import statement at the top program code, which overrides the R.java file in your project. The solution was to simply remove the following import statement:

after the project was saved and rebuilt without issue.

java - Android Google Maps Failed to find style 'mapViewStyle' in curr...

java android google-maps
Rectangle 27 0

My answer may be a late one, but i hope that it'll deals with the actual reason and sure it could be helpful for those who are going to search about the same problem in future.

This type of errors,

1. Android Google Maps Failed to find style 'mapViewStyle' in current theme
2. Failed to find style 'imageButtonStyle' in current theme 
3. Failed to find style 'editTextStyle' in current theme 
4. Failed to find style 'textViewStyle' in current theme

Anything from the above list it may be,

We have selected the unavailable Theme for the layout.

  • The selected theme is not available in themes.xml file.
  • The selected theme is belongs to higher version sdk, but our current target sdk is lower one.
  • when you copy the whole layout file and try to implement it in your project. a. Your may forgot to copy themes.xml file b. You may have lower target sdk, the original layout created with higher target sdk.

(Open and View the layout file in the Graphical Layout View, and look at the top Right corner. There your themes for the layout have been selected.)

  • So click the dropdown list for theme selection and choose the available themes according to your project themes and targeted sdk themes. (OR)
  • If the theme is a custom one , if you are required it , then copy the themes.xml file to your project from the source where you copied the layout xml file. (OR)
  • If the theme is sdk avail theme, if you are required it , then change your target according to your selected theme.

Hope,This might be helpful for somebody.

This is an exact copy of your answer stackoverflow.com/questions/8513278/. This issue is not related to the themes.xml, as the theme is inherited from the Maps API.

java - Android Google Maps Failed to find style 'mapViewStyle' in curr...

java android google-maps
Rectangle 27 0

You can use Location to determine the distance between two addresses:

private static float distance(LatLng current, LatLng last){
    if(last==null)
        return 0;
    Location cL = new Location("");
    cL.setLatitude(current.latitude);
    cL.setLongitude(current.longitude);

    Location lL = new Location("");
    lL.setLatitude(last.latitude);
    lL.setLongitude(last.longitude);

    return lL.distanceTo(cL);
}

Thanks for the reply. After finding the distance, i stored all of them in an arrayList and then found min using Collections.min(). But now how do i keep track of LatLng which corresponds to this min distance?

java - Find the location nearest to current location from an array of ...

java android google-places-api google-maps-android-api-2
Rectangle 27 0

I tried to point this out to the moderators but I was ignored...

this one didn't help as well .. super useless list of links..

@ewoks +1 I totally agree - this was my attempt to get the moderators to combine these questions - they are all totally useless. Unfortunately when I flagged the question as duplicate, the moderator disagreed.

java - Android Google Maps Failed to find style 'mapViewStyle' in curr...

java android google-maps
Rectangle 27 0

If you need the real nearest location, use Location.distanceBetween.

If you have a lot of locations and require code to execute faster, I'd suggest using this formula:

double diffLat = Math.abs(lat1 - lat2);
double diffLng = Math.abs(lng1 - lng2);
if (diffLng > 180) {
    diffLng = 360 - diffLng;
}
double distanceSquared = diffLat * diffLat + diffLng * diffLng;

Don't calculate sqrt of this, as this is not needed to find (approximatelly) the closest location. Just compare squared values.

The if is there because you may have location with -179 and +179 longitude and these are close to each other.

Depending on the data, you may also try algorithms with binary search on sorted data, but there are 2 dimensions here, so it's not as straightforward as finding int in sorted int[].

java - Find the location nearest to current location from an array of ...

java android google-places-api google-maps-android-api-2